electron-webpack
electron-webpack copied to clipboard
Pass through environment variables for use in the ${env} macro in electron-builder
- electron-builder: 21.2.0, electron-webpack: 2.7.4:
- Mac, Windows:
I am utilizing environment variables as defined in the electron-webpack documentation to inject into my app (works great). To build the application I'm using electron-builder and what I'd like to do is utilize the ${env} macro to grab one of the ENV vars I set at the electron webpack level. Is this possible? So for example I want something like this in the electron-builder custom config file.
productName: App Name
appId: app.dev
artifactName: ${productName}.${ext}
directories:
output: apps/${env.ELECTRON_WEBPACK_APP_BUILD}
When I try to build this, I get the following error:
cannot expand pattern "apps/${env.ELECTRON_WEBPACK_APP_BUILD}": env ELECTRON_WEBPACK_APP_BUILD is not defined
Is there a way to pass through the env vars defined in electron-webpack for use as a macro in electron-builder?
It looks like creating an electron-builder.env file in the root directory works, but I don't want to have to maintain it in two places. Looking for a solution.
electron-webpack supports a .env file - maybe you can create a symlink or on postinstall?
Or you could manually init dotenv pointing to electron-builder.env in your entry or webpack config file?
Hi, In my case, .env works without any setting
.env
ELECTRON_WEBPACK_APP_HOGE=123
be careful,
console.log(process.env)
I can not see ELECTRON_WEBPACK_APP_HOGE value
but
console.log(process.env.ELECTRON_WEBPACK_APP_HOGE)
I can see it