According to this it is not possible to set flags within an electron app with environment variables. I still need to build different versions of the app for dev, staging, pilot and prod.
Internally I would like to use electron-node-config because it's just easy. But because I have no access to environment variables it's not possible to use node-config.
So I thought of having several entry scripts like
// index.dev.js
require('./main')({ APP_URL: 'localhost:8080' });
// index.staging.js
require('./main')({ APP_URL: 'https://staging.foo.com' });
// pilot.staging.js
require('./main')({ APP_URL: 'https://pilot.foo.com' });
Where my main.js file looks more or less like this
module.exports = (config) => {
app.on('ready', () => {
mainWindow.loadURL(config.APP_URL);
});
};
However, in the electron builder docs there doesn't seem to be an option for specifying an entry file, it always uses index.js to package the app, and there isn't much written in the docs for the js api other than
const builder = require('electron-builder');
const env = process.env.NODE_ENV;
const entry = `index.${env}.js`;
builder.build({
entry,
appId: 'com.electron.foo',
productName: 'foo',
mac: {
target: 'zip'
},
win: {
target: 'portable'
},
portable: {
artifactName: 'foo.exe'
}
});
So I tried setting up my package.json like this
"scripts": {
"build:staging": "NODE_ENV=development node scripts/build",
"build:pilot": "NODE_ENV=pilot node scripts/build",
"build:production": "NODE_ENV=production node scripts/build"
}
However I'm really not sure how to set the entry file for electron builder config. How do I specify an entry file?
scripts/buildis acctually a yourbuild.js. Thanks a lot for this solution