Hi, I try to make an app with electron-builder and I neet to set NODE_ENV=production.
I use cross-env to set it, I try to put it on my scripts (start, pack and dist) but doesn't work.
Any idea how can I do this ? Do I miss something ?
I made this temporally fix but if any way exist to add env variable to the packed app, it can be awesome !
if (process.env.NODE_ENV == undefined) process.env.NODE_ENV = "production"
Thank's in advance !
In general, it is not possible. Please see https://github.com/electron-userland/electron-builder/issues/1955 for details.
I recommend you to use https://github.com/sindresorhus/electron-is-dev
Is it suitable for you? If not, for what do you need such env for packed app?
Well, you can also use webpack (https://github.com/electron-userland/electron-webpack), but I think electron-is-dev will be enough for you.
Hi, thank's for your quick answer.
I just need that to use node-config, so different config file in production and development.
I'll go with my first solution, thank's again !
Do you want ability — electron-builder should automatically use or electron-builder.dev.yml if NODE_ENV=developement, or electron-builder.production.yml?
Maybe I wasn't clear enough, I just need different conf file in dev and prod.
config/dev.json when I'm testing the app with npm startconfig/prod.json when I launch the app after installationI'm using node-config that load my conf file according to NODE_ENV.
So I set npm start with NODE_ENV=development with this following line at the beginning of my app, it does the tricks for production.
if (process.env.NODE_ENV == undefined) process.env.NODE_ENV = "production"
So electron-builder should always use the same conf file.
not sure if it will help someone but I end up using webpack.DefinePlugin
/**
* Adjust mainConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
mainConfig.plugins.push(
new BabiliWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
})
)
}
it redeclares process.env.NODE_ENV during build script to make it available into the built app
Is it suitable for you? If not, for what do you need such env for packed app?
Late reply but yes, in my app I'm simply doing mainWindow.loadURL(...) but these need to be pointed to different deploy targets...localhost, staging, pilot, etc., prod.
Good. I can't even know this way.
@daniellizik I'm struggling with the same requirement, did you found a solution for it?
@jjtfsalgado I just wrote a script that cached package.json in a temporary file, then modified package.json and ran the build. Ugly but it worked.
Why not just use the get method app.isPackaged
Docs
@alexandermckay that'd work if you only had two environments as the docs suggest. If you have like three or more you need something else.
Most helpful comment
Late reply but yes, in my app I'm simply doing
mainWindow.loadURL(...)but these need to be pointed to different deploy targets...localhost, staging, pilot, etc., prod.