简体   繁体   中英

Overriding the build configuration

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.

  1. First install dotenv - npm install dotenv

  2. Create an .env file in the same folder as package.json

  3. Then create the environment variables starting with → REACT_APP_

    Example of point 3:

    Inside .env file → REACT_APP_URL_PATH=xxxxx

  4. 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 ↓↓↓↓↓

https://www.npmjs.com/package/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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM