Packaging and installers
Users do not run npm start — they need an app with a shortcut or an installer. Electron Forge builds the finished app (a copy of Electron with your code inside) and packs it into installers for different systems. Installers are created by separate modules called makers.
Adding Forge to a hand-made project
If the project was created with npm init electron-app, Forge is already set up. In the project from "A first app by hand" it is added like this:
npm install --save-dev @electron-forge/cli
npx electron-forge importimport installs the needed packages, creates forge.config.js and replaces the scripts in package.json with electron-forge start, package and make.
Building the app
npm run packageA folder like notes-win32-x64 with notes.exe (on macOS — notes.app) appears in out/. It can be started with a double click. The app's code is inside, in the resources/app.asar archive.
The installer
npm run makeThe command runs package first, then the makers for the current system. The result is in out/make/: on Windows there is Setup.exe, on macOS a .zip archive.
Settings
The build is described by forge.config.js:
// forge.config.js
module.exports = {
packagerConfig: {
asar: true,
icon: 'assets/icon',
},
makers: [
{ name: '@electron-forge/maker-squirrel', config: {} },
{ name: '@electron-forge/maker-zip', platforms: ['darwin'] },
{ name: '@electron-forge/maker-deb', config: {} },
],
};icon is given without an extension: Forge uses assets/icon.ico for Windows and assets/icon.icns for macOS. The app's name comes from the productName and version fields of package.json.
Makers
| Maker | System | Result |
|---|---|---|
maker-squirrel | Windows | A Setup.exe installer |
maker-zip | macOS, Windows, Linux | A .zip archive |
maker-dmg | macOS | A .dmg disk image |
maker-deb | Debian, Ubuntu | A .deb package |
maker-rpm | Fedora | An .rpm package |
Each maker is a separate npm package, e.g. npm install --save-dev @electron-forge/maker-dmg.
Building for other systems
An installer for a system is usually built on that system: for macOS on a Mac, for Windows on Windows. To avoid keeping three computers, a continuous integration service such as GitHub Actions runs the job on machines with different systems.
Common mistake
Forge puts only dependencies into the app and drops devDependencies. If a library the main process needs is installed with --save-dev, the app works with npm start but fails after building with Cannot find module. Install what the app needs at run time with a plain npm install.