I have an environment variable that I need to access inside my render method. Since its a custom ENV variable, I cannot use (process.env.NODE_ENV). I have read that React sanitises all process.env access.
How to access my custom environment variable (CLUSTER_ENV) inside React web app?
I have an environment variable that I need to access inside my render method. Since its a custom ENV variable, I cannot use (process.env.NODE_ENV). I have read that React sanitises all process.env access.
How to access my custom environment variable (CLUSTER_ENV) inside React web app?
Share Improve this question edited May 14, 2018 at 9:27 Martijn 16.1k4 gold badges38 silver badges72 bronze badges asked Sep 19, 2017 at 10:53 SeaWarrior404SeaWarrior404 4,16716 gold badges47 silver badges66 bronze badges 01 Answer
Reset to default 13If you are using webpack, it is possible with Webpack Define plugin.
webpack.config.js:
...
plugins: [
new webpack.DefinePlugin({
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
...
and then simply you can use on your javascript file.
console.log(NODE_ENV);
edit: not alias, define plugin.