I'm setting up ReactJS Project to change environment variables at Run-time.
I have 2 ENV variables:
1) NODE_ENV = Production, Development
2) FLAVOUR = Alpha, Beta
I want to load different configurations, theme and images based on FLAVOUR
variable. Which is already done and working.
Build commands:
1) cross-env NODE_ENV=production --env.FLAVOUR=Alpha webpack
2) cross-env NODE_ENV=production --env.FLAVOUR=Beta webpack
--
But above commands are changing env variables at Build-Time. But I want to change FLAVOUR
variable only for Production env at Run-Time after the build.
Ex. ./build cross-env --env.FLAVOUR=Alpha node server
Ex. ./build cross-env --env.FLAVOUR=Beta node server
./build is build directory, created by npm run build command.
--
Which means when I change the FLAVOUR
variable to Beta
and restart the web app
My expectation is that it will be the Beta
app and Theme.
This helps us with scaling these webapps. They can be re-purposed on a dime.
Webpack Production:
new webpack.DefinePlugin({
'process.env.FLAVOUR': JSON.stringify(process.env.FLAVOUR),
})