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:Available Hooks
beforePack
function | string
The function (or path to file or module id) to be run before pack.Function signature:Context properties:As external file:
outDir- The output directoryappOutDir- The application output directorypackager- The platform packager instanceelectronPlatformName- The Electron platform name (e.g., ‘darwin’, ‘win32’, ‘linux’)arch- The architecture being builttargets- Array of build targets
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 pathtarget- The build targetarch- The architecturepackager- The platform packager instance
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 Example:
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.onNodeModuleFile
function | string
The function (or path to file or module id) to be run on each node module file.Returning Example:
true will force include the file, false will exclude it, and undefined will use the default copier logic.Function signature: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., Example:
~/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.Common Hook Use Cases
Custom File Processing
Environment-Specific Configuration
Generating Checksums
Platform-Specific Logic
Best Practices
- Keep hooks fast - Hooks run during the build process, so keep them as efficient as possible
- Handle errors properly - Always use try-catch blocks and provide meaningful error messages
- Use async/await - Prefer async/await over callbacks for better readability
- Log important actions - Use console.log to track what your hooks are doing
- Test thoroughly - Test hooks with different platforms and configurations
Debugging Hooks
To debug hooks, add verbose logging:--verbose flag for additional output: