electron-builder

repository·master·Indexed 12 days ago

https://github.com/electron-userland/electron-builder

A complete solution for packaging and building Electron applications for macOS, Windows, and Linux, featuring out-of-the-box support for auto-updates. Includes tools like electron-updater for automatic updates, electron-publish for artifact distribution, and support for various targets including NSIS, AppImage, Snap, and Squirrel.Windows.

Tokens
101.9K
Snippets
317
Records
466
Agent score
96%

What's inside electron-builder

  1. Overview of Linux build targets

    master

    electron-builder supports multiple Linux package formats. You should choose a target based on your distribution method and target audience:

    • AppImage: Single file, universal compatibility, no installation required. (Default)
    • deb: Debian package for Ubuntu, Debian, and Mint.
    • rpm: RPM package for Fedora, RHEL, and openSUSE.
    • snap: Snap package for Ubuntu-primary environments (requires snapd). (Default)
    • flatpak: Cross-distro sandboxed format (requires flatpak).
    • pacman: Arch Linux package (currently in Beta).
    • apk: Alpine Linux package (useful for containers).
    • freebsd: FreeBSD package.
    • p5p: Solaris IPS package.
    • Archives (zip, 7z, tar.*): For custom CDN distribution.
    • dir: Directory format for development and debugging.
  2. Use electron-forge-maker-nsis for Electron Forge NSIS targets

    master

    The electron-forge-maker-nsis package provides an NSIS target for projects using Electron Forge.

    Important Recommendation: It is highly recommended to build Electron Forge projects using electron-builder directly instead of using this maker. Using electron-builder directly ensures full support for critical features including:

  3. New features in electron-builder v27

    master

    Version 27 introduced several new capabilities:

    • MSIX target (beta): Use win.target: "msix" to produce .msix, .msixbundle, or .msixupload artifacts with modern manifest features.
    • Cloudflare R2 publish provider: An S3-compatible provider: "r2" target. Requires CF_R2_ACCESS_KEY_ID and CF_R2_SECRET_ACCESS_KEY environment variables.
    • Windows PKCS#11 & HSM code signing (beta): New win.sign modes: pkcs11 (cross-platform via osslsigncode) and hsm (Windows CSP / FIPS token).
    • DMG ULMO / LZMA format: Use dmg.format: "ULMO" for LZMA-compressed images (macOS 10.15+), which are typically ~30% smaller than the default UDZO.
    • electron-updater allowUnverifiedLinuxPackages: A new AppUpdater flag to enforce GPG signature checks for .deb / .rpm auto-updates (defaults to true).
    • Native ESM: All packages now ship as native ES modules. On Node.js 22.12.0+, both import and CJS require() are supported.
  4. Use electron-forge-maker-nsis-web for NSIS web targets in Electron Forge

    master

    The electron-forge-maker-nsis-web package provides an NSIS web target for projects using Electron Forge.

    Important Note: It is highly recommended to build Electron Forge projects using electron-builder directly instead of using this maker. Many critical features are only supported when using electron-builder directly, including:

  5. What is MSI-Wrapped and when to use it

    master

    MSI-Wrapped is a hybrid packaging approach that wraps a standard NSIS .exe installer inside a minimal MSI shell. This allows you to leverage the full customization capabilities of NSIS while providing an MSI package that enterprise IT teams can deploy via tools like Group Policy, SCCM, or Intune.

    When to use MSI-Wrapped:

    • You have an existing NSIS configuration and need MSI deployment compatibility.
    • You want to avoid maintaining a separate, complex WiX-based native MSI configuration.
    • You need NSIS-level UI customization combined with enterprise deployment support.

    When to use Native MSI instead:

    • You require advanced MSI features like custom actions, rollback, or MSI database manipulation.
    • You are targeting Windows Store / MSIX conversion.
    • You need clean per-machine/per-user support without relying on NSIS.
  6. How build hooks work in electron-builder

    master

    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)
      }
    }
  7. Ensure reliable window association with desktopName

    master

    To ensure desktop environments (GNOME, KDE, etc.) correctly link running windows to their launcher icons and taskbar entries, you must set the desktopName field in your root package.json.

    Electron derives the window's WM_CLASS from this field. If desktopName is missing, electron-builder will log a warning, and the association may break because the fallback WM_CLASS might not match the installed .desktop filename.

    // package.json
    {
      "desktopName": "com.example.MyApp"
    }
  8. Manage ASAR and native modules with asar.unpack

    master

    ASAR (Atom Shell Archive) is Electron's optimized archive format for bundling application source files. Because files inside ASAR are read through a virtual filesystem, native modules (.node files) or large binaries that require direct filesystem access cannot be run from within the archive.

    To fix this, use the asar.unpack configuration option to provide glob patterns for files that should be placed in app.asar.unpacked/ instead of being bundled inside the ASAR archive.