If you have a react app you can use env vars like
REACT_APP_MY_ENV_VAR in your application and React will automatically pull them in to your app when you build the production application.
This is very useful but if you have variables that change for each environment and your application build takes a long time, you might want to avoid building unnecessarily in CI. For example you might have a QA environment and a Staging environment that have different configuration.
We type-check our code on each build and that was taking 5 minutes+ to build each environment so we had to make it faster. We changed our app from using
REACT_APP env vars to using a configuration file that we could quickly write to using CI.
Our CI system is Azure DevOops so the CI scripts here are specifically for Azure DevOps but they apply to most CI systems with small changes.
The real work happens in a Node.js script that would work anywhere.