Skip to main content
Build hooks allow you to execute custom code at various stages of the electron-builder build process. Hooks can be defined as functions directly in the configuration or as paths to external modules.
All examples assume you are using Node.js 8.11.x or higher.

Hook Configuration

Hooks can be specified in two ways:

As a Function (JS/TS config only)

As a Path to Module

When using JSON or YAML configuration, specify the path to a file that exports the hook function:
The hook file should export the function as the default export:

Available Hooks

beforePack

function | string
The function (or path to file or module id) to be run before pack.Function signature:
Context properties:
  • outDir - The output directory
  • appOutDir - The application output directory
  • packager - The platform packager instance
  • electronPlatformName - The Electron platform name (e.g., ‘darwin’, ‘win32’, ‘linux’)
  • arch - The architecture being built
  • targets - Array of build targets
Example:
As external file:

afterExtract

function | string
The function (or path to file or module id) to be run after the prebuilt Electron binary has been extracted to the output directory.Function signature:
This hook is useful for modifying the Electron binary or adding custom files before the app is packaged.Example:

afterPack

function | string
The function (or path to file or module id) to be run after pack (but before pack into distributable format and sign).Function signature:
This is one of the most commonly used hooks, allowing you to modify the packaged app before it’s signed and distributed.Example:

afterSign

function | string
The function (or path to file or module id) to be run after pack and sign (but before pack into distributable format).Function signature:
This hook is particularly useful for notarizing macOS applications.Example - macOS Notarization:
As external file:

artifactBuildStarted

function | string
The function (or path to file or module id) to be run when artifact build starts.Function signature:
Example:

artifactBuildCompleted

function | string
The function (or path to file or module id) to be run when artifact build completes.Function signature:
Context properties:
  • file - The output file path
  • target - The build target
  • arch - The architecture
  • packager - The platform packager instance
Example:

afterAllArtifactBuild

function | string
The function (or path to file or module id) to be run after all artifacts are built.Function signature:
This hook can return an array of additional files to publish.Example:
As external file:

beforeBuild

function | string
The function (or path to file or module id) to be run before dependencies are installed or rebuilt.Works when npmRebuild is set to true. Resolving to false will skip dependencies install or rebuild.Function signature:
If provided and node_modules are missing, it will not invoke production dependencies check.
Example:

onNodeModuleFile

function | string
The function (or path to file or module id) to be run on each node module file.Returning true will force include the file, false will exclude it, and undefined will use the default copier logic.Function signature:
Example:

msiProjectCreated

function | string
The function (or path to file or module id) to be run after MSI project is created on disk (not packed into .msi package yet).Function signature:
Example:

appxManifestCreated

function | string
The function (or path to file or module id) to be run after Appx manifest is created on disk (not packed into .appx package yet).Function signature:
Example:

electronDist

function | string
The function (or path to file or module id) to be run when staging the Electron artifact environment.Returns the path to custom Electron build (e.g., ~/electron/out/R) or folder of Electron zips.Function signature:
Zip files must follow the pattern electron-v${version}-${platformName}-${arch}.zip, otherwise it will be assumed to be an unpacked Electron app directory.
Example:

Common Hook Use Cases

Custom File Processing

Environment-Specific Configuration

Generating Checksums

Platform-Specific Logic

Best Practices

  1. Keep hooks fast - Hooks run during the build process, so keep them as efficient as possible
  2. Handle errors properly - Always use try-catch blocks and provide meaningful error messages
  3. Use async/await - Prefer async/await over callbacks for better readability
  4. Log important actions - Use console.log to track what your hooks are doing
  5. Test thoroughly - Test hooks with different platforms and configurations
Be careful when modifying files in hooks, especially signed files. Modifying signed binaries will invalidate signatures.

Debugging Hooks

To debug hooks, add verbose logging:
Run electron-builder with the --verbose flag for additional output: