I see here that arguments can be passed through to electron-forge start (eg. via electron-forge start -- role=production) but can't seem to find out how to do so through the electron-forge make command.
Would appreciate being pointed in the right direction.
Check out electron-forge make --help for any arguments you can pass. If you're talking about the packaged Electron app, arguments should just pass through into process.argv.
I did that and see the limited number of options. How can I go about having arguments passed through to the package Electron app while going through the make/forge process?
Take a look at https://github.com/electron-userland/electron-forge#config, specifically https://github.com/electron-userland/electron-forge#configuring-package for Electron Packager config.
Let me know if that's confusing and what we could do to improve.
I looked at both of those quiet a bit before posting here, and maybe I'm missing something obvious, but I can't seem to figure out how to ensure a specific param is passed through when the electron-forge publish command is issued.
Could you give an example?
Sure. Here's how I open up the Electron app while testing:
electron-forge start -- role=production
I pass in an the argument role=production so that the code can load proper logic.
However when calling electron-forge publish -- role=production the argument doesn't get passed into the app while is getting compiled and packaged.
@onassar That's not possible, arguments are provided at runtime and can't be "preconfigured". If you want to set variables like that you should do something like so.
MY_APP_ROLE) and set it to the value you wantgenerateAssets hook to create a file containing that informationThis would look like so
// package.json
{
"scripts": {
"make": "MY_APP_ROLE=prod electron-forge make"
}
}
// forge.config.js
module.exports = {
hooks: {
generateAssets: async () => {
fs.writeFileSync(
'./role.json',
JSON.stringify({
role: process.env.MY_APP_ROLE
})
);
}
}
}
// main.js
const { role } = require('./role.json');
Hmm okay let me look into that and get back to this thread. Thanks for jumping on this so quick @MarshallOfSound
@MarshallOfSound I haven't used the module.exports syntax before? That's inside of forge.config.js? And how does that get referenced from package.json?
I haven't used the
module.exportssyntax before? That's inside offorge.config.js?
That's correct, forge.config.js is just a JavaScript file (as opposed to a JSON file) that exports functions and properties just like any other JavaScript module.
And how does that get referenced from
package.json?
A very abbreviated version of package.json:
{
"name": "myElectronApp",
"config": {
"forge": "forge.config.js"
}
}
Okay great I'll try that and update shortly after. Y'all are great!
Okay I figured out the module.exports approach, but struggling with this:
// package.json
{
"scripts": {
"make": "MY_APP_ROLE=prod electron-forge make"
}
}
The issue is I want to package/make/publish for different env's via CLI, and so I want to be able to pull in the role dynamically. Has anyone tried this?
@onassar If you want to do it dynamically you can pass arbitrary arguments to electron-forge make and then read them in inside your config file. I.e.
// package.json
{
"scripts": {
"make": "electron-forge make"
}
}
npm run make -- --role=prod
// forge.config.js
const role = process.argv.find(arg => arg.startsWith('--role='));
Ahh okay that makes sense. Really appreciate it @MarshallOfSound
While I'm here (and happy to open a separate issue on StackOverflow if that's more in line), it seems when packaging up for darwin, the original directory (with source) is being copied into the file. This surprises me since the default value for asar is false (and I haven't overwritten it).
Am I off on that?
Here's a screenshot of that:

^^ That's 100% expected? If ASAR is false the entire directory is copied, when ASAR is true it is put in an ASAR file instead (app.asar)
Oh jeez I've been at it too long today lol
Totally missed that. You're right: setting ... "asar": true ... created the archive.
Is that archive secure enough if it contains sensitive info?
Define "sensitive info", anything in there can be read by anyone who knows how. ASAR is not a security / obscurity thing. It is just a packaging format
It was an AWS key for packaging. But I decided to use the ignore option here:
https://github.com/electron-userland/electron-packager/blob/master/docs/api.md
That did the trick! Thanks so much for all the help @MarshallOfSound & @malept
You made this cowpoke a little less intimidated of Electron ;)
Is there a way to change the file name pattern? I was trying to make a macOS application (zip), the name was always ProductName-darwin-x64-version.zip. How can I change the name to ProductName.zip? Thanks.
I would think the easiest would be just to run a cli call?
I just use electron-forge make. Could you please be more specific @onassar ? I tried to use name field in electronPackagerConfig, but the name pattern of the zip file won't change. Thank you.
There's a postMake hook you could use. Unfortunately, it isn't documented in 5.x. It looks like you need to add:
forge: {
hooks: {
postMake: function (outputs) { /* code that probably modifies outputs */ }
}
}
where outputs is an array of:
Most helpful comment
I did that and see the limited number of options. How can I go about having arguments passed through to the package Electron app while going through the make/forge process?