Build hooks allow you to execute custom code at specific stages of the electron-builder lifecycle. This is useful for modifying app bundles, performing custom code signing, uploading debug symbols, or integrating with external services like Sentry.
Hooks are executed serially for each platform/architecture combination. If a hook is asynchronous, electron-builder will await its completion before proceeding. If a hook throws an error, the entire build process will fail.
Key Lifecycle Stages:
- Pre-build:
beforeBuild (before native deps are installed). - Packaging:
beforePack (before files are copied), afterExtract (after Electron binary extraction), afterPack (after files are packaged, but before signing). - Signing:
afterSign (after signing, but before distributable creation). - Artifact Generation:
artifactBuildStarted, artifactBuildCompleted, and afterAllArtifactBuild (after all installers/images are finished).
// Example of a simple hook in a JS config
module.exports = {
afterPack: async (context) => {
console.log("afterPack:", context.appOutDir)
}
}