electron-webpack icon indicating copy to clipboard operation
electron-webpack copied to clipboard

Pass through environment variables for use in the ${env} macro in electron-builder

Open jsheffers opened this issue 6 years ago • 4 comments

  • 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?

jsheffers avatar Oct 22 '19 17:10 jsheffers

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.

jsheffers avatar Oct 22 '19 18:10 jsheffers

electron-webpack supports a .env file - maybe you can create a symlink or on postinstall?

loopmode avatar Oct 22 '19 19:10 loopmode

Or you could manually init dotenv pointing to electron-builder.env in your entry or webpack config file?

loopmode avatar Oct 22 '19 19:10 loopmode

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

azamiya avatar Jul 25 '21 06:07 azamiya