Electron Forge
  • Getting Started
  • Importing an Existing Project
  • CLI
  • Core Concepts
    • Why Electron Forge?
    • Build Lifecycle
  • Configuration
    • Configuration Overview
    • TypeScript Setup
    • Plugins
      • Webpack Plugin
      • Vite Plugin
      • Electronegativity Plugin
      • Auto Unpack Native Modules Plugin
      • Local Electron Plugin
      • Fuses Plugin
    • Makers
      • AppX
      • deb
      • DMG
      • Flatpak
      • pkg
      • RPM
      • Snapcraft
      • Squirrel.Windows
      • WiX MSI
      • ZIP
    • Publishers
      • Bitbucket
      • Electron Release Server
      • GitHub
      • Google Cloud Storage
      • Nucleus
      • S3
      • Snapcraft
    • Hooks
  • Built-in Templates
    • Webpack
    • Webpack + Typescript
    • Vite
    • Vite + TypeScript
  • Guides
    • Code Signing
      • Signing a Windows app
      • Signing a macOS app
    • Custom App Icons
    • Framework Integration
      • React
      • React with TypeScript
      • Vue 3
    • Developing with WSL
  • Advanced
    • Auto Update
    • Debugging
    • Extending Electron Forge
      • Writing Plugins
      • Writing Templates
      • Writing Makers
      • Writing Publishers
    • API Docs
Powered by GitBook
On this page
  • getHooks(): ForgeMultiHookMap
  • startLogic(startOpts: StartOptions): Promise<ChildProcess | false>

Was this helpful?

Edit on GitHub
  1. Advanced
  2. Extending Electron Forge

Writing Plugins

PreviousExtending Electron ForgeNextWriting Templates

Last updated 3 months ago

Was this helpful?

An Electron Forge Plugin has to export a single class that extends our base plugin. The base plugin can be depended on by installing@electron-forge/plugin-base. It can implement two methods, neither are required.

getHooks(): ForgeMultiHookMap

If implemented this method will be once during plugin initialization inside Forge, this method is called only once and shouldn't result in any side effects being executed. You must return an object in a similar format to forgeConfig.hooks. i.e. an object map between hook names and an array of hook functions.

The possible hook names and the parameters passed to the hook function you return are documented over in the section of the docs.

export default class MyPlugin extends PluginBase {
  getHooks () {
    return {
      prePackage: [this.prePackage]
    };
  }

  prePackage () {
    console.log('running prePackage hook');
  }
}

startLogic(startOpts: StartOptions): Promise<ChildProcess | false>

If implemented, this method will be called every time the user runs electron-forge start, if you return a ChildProcess you can override the built in start logic and Electron Forge will not spawn it's own process, rather it will watch the one you returned. If you return false forge will spawn Electron itself but you could still run custom logic such as started compilation for code or downloading certain binaries before the app starts.

Please note that overriding the start logic here only works in development if you want to change how an app runs once packaged you will need to use a build hook to inject code into the packaged app.

export default class MyPlugin extends Pluginbase {
  async startLogic (opts) {
    await this.compileMainProcess();
    return null;
  }

  compileMainProcess () { /* ... */ }
}

StartOptionsis explained further .

Configuration
in the API docs