Overview

How to configure Electron Forge

Electron Forge configuration is centralized in a single configuration object. You can specify this config in your package.json on the config.forge property. This property can be in one of two forms:

  • An object containing your entire Forge configuration.

  • A relative path pointing at a JavaScript file that exports your config.

If you do not have config.forge set in your package.json file, Forge will attempt to find a forge.config.js file in your project root.

forge.config.js
module.exports = {
  packagerConfig: {},
  makers: [
    {
      name: '@electron-forge/maker-zip'
    }
  ]
};

We recommend using JavaScript for your config file since it enables conditional logic within your configuration.

Configuration options

module.exports = {
  packagerConfig: { /* ... */ },
  rebuildConfig: { /* ... */ },
  makers: [],
  publishers: [],
  plugins: [],
  hooks: { /* ... */ },
  buildIdentifier: 'my-build'
};

All properties in your Forge configuration are optional. Initializing your project with one of the built-in templates will include some default recommended config options.

Electron Packager config

The top level property packagerConfig on the configuration object maps directly to the options sent to @electron/packager during the Package step of Electron Forge's build process

This configuration allows you customize how @electron/packager bundles your Electron-based application source code into a packaged application ready for distribution.

forge.config.js
module.exports = {
  packagerConfig: {
    name: 'My Electron App',
    asar: true,
    osxSign: {},
    appCategoryType: 'public.app-category.developer-tools'
  }
};

The options you can put in this object are documented in the Electron Packager API docs.

You can not override the dir, arch, platform, out or electronVersion options as they are set by Electron Forge internally.

If you want to specify a platform/architecture combination for any build command (Package, Make, or Publish), you can specify --arch and --platform flags using the Forge CLI (e.g. npm run make --arch=arm64).

See the Build commands documentation for more details.

Electron Rebuild config

The top level property rebuildConfig on the configuration object maps directly to the options sent to @electron/rebuild during both the Package and Start commands in Electron Forge.

This configuration allows you to customize how Electron Forge rebuilds your project's native Node.js modules against the Node.js version bundled in your app's Electron version.

forge.config.js
module.exports = {
  rebuildConfig: {
    force: true
  }
};

The options you can put in this object are documented in the Electron Rebuild API docs.

The required buildPath and electronVersion options for @electron/rebuild are preconfigured by Forge. The optional arch option will also be overridden by Forge internally.

Makers

The top-level makers property on the configuration object is an array of maker configurations. Each maker will generate a distributable artifact for your packaged application in the Make step (e.g. Squirrel.Windows on Windows or DMG on macOS).

Check out the Makers documentation for all official makers and their config options, and theWriting Makers guide for implementing your own Make step build targets.

forge.config.js
module.exports = {
  makers: [
    {
      name: '@electron-forge/maker-zip',
      platforms: ['darwin']
    }
  ]
};

Publishers

The top level property publishers on the configuration object is an array of publisher configurations. Each publisher provides a publish target for your distributable (e.g. GitHub or S3).

Check out the Publishers documentation for all official publishers and their config options, and the Writing Publishers guide for implementing your own custom Publish targets.

forge.config.js
module.exports = {
  publishers: [
    {
      name: '@electron-forge/publisher-github',
      config: {
        repository: {
          owner: 'electron',
          name: 'fiddle'
        },
        draft: true,
        prerelease: false,
        generateReleaseNotes: true
      }
    }
  ]
};

Plugins

The top level property plugins on the configuration object is an array of plugin configurations. Electron Forge plugins can hook into any point in its lifecycle and provide additional functionality (e.g. the Webpack Plugin will integrate webpack bundling into the build lifecycle, and the Electronegativity Plugin will identify security anti-patterns in your app).

Check out the Plugins documentation for all possible plugins and their config options, and the Writing Plugins guide for implementing your own custom Forge plugins.

Hooks

The top level property hooks on the configuration object is an object containing hooks that can be used to insert custom logic during the Build Lifecycle.

Check out the Hooks documentation for all possible hooks and their config options.

Build identifiers

This property can be used to identify different build configurations. Normally, this property is set to the channel the build will release to, or some other unique identifier. For example, common values are prod and beta. This identifier can be used in conjunction with the fromBuildIdentifier function to generate release channel or environment specific configuration. For example:

forge.config.js
const { utils: { fromBuildIdentifier } } = require('@electron-forge/core');

module.exports = {
  buildIdentifier: process.env.IS_BETA ? 'beta' : 'prod',
  packagerConfig: {
    appBundleId: fromBuildIdentifier({ beta: 'com.beta.app', prod: 'com.app' })
  }
};

In this example the appBundleId option passed to Electron Packager will be selected based on the buildIdentifier based on whether you are building for prod or beta. This allows you to make shared configs incredibly easily as only the values that change need to be wrapped with this function.

Last updated