Reputation: 1260
Is it possible to override the variables inside .env on run or build?
Content of the .env file
REACT_APP_REGIONALIZED_BASE_API_URL=http://hello-default.net
Command script in package.json
"scripts": {
"start:production": "env-cmd -f .env react-scripts start",
}
Sample start command executed in terminal or even in ci/cd pipeline where you have instances based on regions
REACT_APP_REGIONALIZED_BASE_API_URL=http://hello-eu.net yarn start:production
So, instead of having a build with api url http://hello-default.net
, it should have http://hello-eu.net
Upvotes: 3
Views: 1741
Reputation: 1260
Sharing the [alternative] solution I discovered. Just need to add --no-override
argument. This will prevent replacing of the already set variable. Also applicable with multiple env files.
"scripts": {
"start:production": "env-cmd --no-override -f .env react-scripts start",
}
Upvotes: 0