Reputation: 31
I use cra, and pass variables through the .env file. During the building process webpack replace the references to the process.env... with the values form the .env file and chunk contains 'hardcoded' values as a result, that's why I have to rebuild application every time to deploy it to the different environments.
How can I configurate webpack in such a way to don't rebuild whole app just to change environment variables?
Upvotes: 3
Views: 2796
Reputation: 633
Your built React app is just a bunch of static JavaScript files. If you want to vary what gets baked into your static bundle, you need to rebuild the app.
If you want to dynamically load in environment variables, you'll need to render your JavaScript on the server.
Alternatively, build the JavaScript bundle as part of a deployment pipeline so it's automated for you. Tools like Netlify do this for you, and allow you to configure the env vars to pass in.
Upvotes: 2