Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/electron-userland/electron-builder/llms.txt

Use this file to discover all available pages before exploring further.

The main electron-builder module exports the primary build functions and re-exports types from app-builder-lib.

Installation

npm install electron-builder --save-dev

Main Functions

build()

Builds the application for the specified platforms and targets.
function build(
  options: PackagerOptions & PublishOptions,
  packager?: Packager
): Promise<Array<string>>
options
PackagerOptions & PublishOptions
required
Combined build and publish options.
packager
Packager
Optional Packager instance.
Returns: Promise<Array<string>> - Array of artifact paths. Example:
const { build, Platform } = require("electron-builder")

build({
  targets: Platform.MAC.createTarget(),
  config: {
    appId: "com.example.app"
  }
})

createTargets()

Creates a target map for specified platforms.
function createTargets(
  platforms: Array<Platform>,
  type?: string | null,
  arch?: string | null
): Map<Platform, Map<Arch, Array<string>>>
platforms
Array<Platform>
required
Array of platforms to build for (e.g., [Platform.MAC, Platform.WINDOWS]).
type
string | null
Target type (e.g., "dmg", "nsis"). If null, builds default targets.
arch
string | null
Architecture: "x64", "arm64", "ia32", "armv7l", or "all".
Returns: Target map for use with build(). Example:
const { createTargets, Platform } = require("electron-builder")

const targets = createTargets(
  [Platform.MAC, Platform.WINDOWS],
  "dmg",
  "x64"
)

Platform Class

Represents a build platform.

Static Properties

Platform.MAC
Platform
macOS platform instance.
Platform.WINDOWS
Platform
Windows platform instance.
Platform.LINUX
Platform
Linux platform instance.

Methods

createTarget()

Creates targets for this platform.
createTarget(
  type?: string | Array<string> | null,
  ...archs: Array<Arch>
): Map<Platform, Map<Arch, Array<string>>>
type
string | Array<string> | null
Target type(s) (e.g., "dmg", ["dmg", "zip"]).
archs
...Array<Arch>
Architectures to build for.
Example:
const { Platform, Arch } = require("electron-builder")

// Default target, current architecture
Platform.MAC.createTarget()

// Specific targets
Platform.MAC.createTarget(["dmg", "zip"])

// Specific architectures
Platform.MAC.createTarget("dmg", Arch.x64, Arch.arm64)

fromString()

Converts a string to a Platform instance.
static fromString(name: string): Platform
name
string
required
Platform name: "mac", "darwin", "win", "win32", "windows", or "linux".
Example:
const platform = Platform.fromString("mac")

Arch Enum

Architecture enumeration.
enum Arch {
  ia32 = 0,
  x64 = 1,
  armv7l = 2,
  arm64 = 3,
  universal = 4
}

Functions

archFromString()

Converts a string to an Arch value.
function archFromString(name: string): Arch
name
string
required
Architecture name: "ia32", "x64", "armv7l", "arm64", or "universal".

getArchSuffix()

Gets the suffix for an architecture.
function getArchSuffix(arch: Arch, defaultArchs?: Array<Arch>): string

Exported Types

The module re-exports all types from app-builder-lib:

Configuration Types

  • Configuration - Main configuration interface
  • MacConfiguration - macOS-specific options
  • WindowsConfiguration - Windows-specific options
  • LinuxConfiguration - Linux-specific options
  • PlatformSpecificBuildOptions - Common platform options

Target Options

  • DmgOptions - DMG target options
  • PkgOptions - PKG target options
  • NsisOptions - NSIS installer options
  • NsisWebOptions - NSIS web installer options
  • PortableOptions - Portable app options
  • AppImageOptions - AppImage options
  • SnapOptions - Snap package options
  • DebOptions - Debian package options
  • AppXOptions - AppX package options
  • MsiOptions - MSI installer options
  • SquirrelWindowsOptions - Squirrel.Windows options

Core Types

  • Packager - Main packager class
  • BuildResult - Build result interface
  • PackagerOptions - Packager options
  • Target - Build target abstract class
  • TargetConfiguration - Target configuration
  • BeforeBuildContext - Before build hook context
  • AfterPackContext - After pack hook context

File and Asset Types

  • FileAssociation - File association configuration
  • Protocol - URL protocol configuration
  • FileSet - File set specification
  • AsarOptions - ASAR archive options

Metadata Types

  • Metadata - package.json metadata
  • AuthorMetadata - Author information
  • RepositoryInfo - Repository information
  • AppInfo - Application information

Code Signing

  • WindowsSignOptions - Windows code signing
  • CustomWindowsSign - Custom Windows signing
  • CustomMacSign - Custom macOS signing

Artifact Events

  • ArtifactCreated - Artifact creation event
  • ArtifactBuildStarted - Artifact build start event

Publishing

  • PublishOptions - Publishing options
  • PublishManager - Publish manager class
  • UploadTask - Upload task interface

Platform Packagers

  • MacPackager - macOS packager
  • WinPackager - Windows packager
  • LinuxPackager - Linux packager

Utilities

  • CancellationToken - Cancellation token
  • ProgressInfo - Download progress info
  • log - Logger utility

Import Examples

CommonJS

const builder = require("electron-builder")
const { build, Platform, Arch, createTargets } = require("electron-builder")

ES Modules / TypeScript

import * as builder from "electron-builder"
import { build, Platform, Arch, createTargets } from "electron-builder"
import type { Configuration, PackagerOptions } from "electron-builder"

See Also