As far as I know, you cannot transfer env vars to a packaged electronic application at startup (unless you want your users to always launch it from the command line and transfer it themselves). You can always set this env in your application as follows: process.env.NODE_ENV = 'production'. You can integrate this with the electronic packer by having an env file that is installed in your assembly and is required by your application to determine which environment it is in.
For example, you have a script package that looks like this:
"package": "cp env-prod.json src/env.json && npm run build"
and in your file src/main.js:
const appEnv = require('./env.json');
console.log(appEnv)
if(appEnv.env === 'prod') {
process.env.NODE_ENV = 'production';
}
However, I think the easiest way would be to check electron-prebuiltinprocess.execPath
const isProd = process.execPath.search('electron-prebuilt') === -1;
source
share