Currently I am developing a react application. I have created a .env file and am using the environment variables in all other pages but am not able to see the .env file in the build folder. Is there any way to change the environment variables at run time in the build file?
This will work when changing the hostname and port, etc. manually and then cresting the build. Is there any way to change the variables after creation of the build?
Any help will appropriated.
Thanks, Riya
The answer to your question can be found here:
Create React App Docs: Adding Custom Environment Variables
The environment variables are embedded during the build time. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like described here. Alternatively you can rebuild the app on the server anytime you change them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With