I am working on a react/electron project with webpack for bundling and electron-builder to compile the build. I am trying to override the build configuration after its compiled by providing a custom configuration file in the install directory of the application to override the env variables. I have verified process.env
updates but the config variables still use the old configuration which was used at the time of compilation. Is there any way this can be achieved?
For example
const apiKey = process.env.APIKEY
In this case process.env.APIKEY
has the updated config but apiKey
still points to the older key used at the time of compiling the build.
First install dotenv - npm install dotenv
Create an .env
file in the same folder as package.json
Then create the environment variables starting with → REACT_APP_
Example of point 3:
Inside .env
file → REACT_APP_URL_PATH=xxxxx
Start your project locally and add some console.log(process.env.REACT_APP_URL_PATH)
just to check.
5.- Do the electron thing.
↓↓↓↓↓ npm dotenv
↓↓↓↓↓
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.