Skip to main content
The PackagerOptions interface defines options for creating and configuring a Packager instance. Source: packages/app-builder-lib/src/packagerApi.ts:9

Interface Definition

interface PackagerOptions {
  targets?: Map<Platform, Map<Arch, Array<string>>>
  mac?: Array<string>
  linux?: Array<string>
  win?: Array<string>
  projectDir?: string | null
  platformPackagerFactory?: ((info: Packager, platform: Platform) => PlatformPackager<any>) | null
  readonly config?: Configuration | string | null
  readonly effectiveOptionComputed?: (options: any) => Promise<boolean>
  readonly prepackaged?: string | null
}

Properties

Target Configuration

targets
Map<Platform, Map<Arch, Array<string>>>
Target configuration map. Use Platform.createTarget() or createTargets() to create this structure.Example:
const targets = Platform.MAC.createTarget(["dmg", "zip"], Arch.x64, Arch.arm64)
mac
Array<string>
Array of macOS target names. Alternative to using targets.Example:
mac: ["dmg", "zip", "pkg"]
Supported targets:
  • dmg - DMG installer
  • zip - ZIP archive
  • pkg - PKG installer
  • mas - Mac App Store
  • mas-dev - Mac App Store (development)
win
Array<string>
Array of Windows target names. Alternative to using targets.Example:
win: ["nsis", "portable", "appx"]
Supported targets:
  • nsis - NSIS installer
  • nsis-web - NSIS web installer
  • portable - Portable executable
  • appx - AppX package (Windows Store)
  • msi - MSI installer
  • squirrel - Squirrel.Windows
  • dir - Unpacked directory
linux
Array<string>
Array of Linux target names. Alternative to using targets.Example:
linux: ["AppImage", "deb", "rpm", "snap"]
Supported targets:
  • AppImage - AppImage package
  • snap - Snap package
  • deb - Debian package
  • rpm - RPM package
  • pacman - Pacman package
  • flatpak - Flatpak package
  • dir - Unpacked directory

Project Configuration

projectDir
string | null
The path to the project directory. Defaults to the current working directory.Example:
projectDir: "/path/to/my/project"
config
Configuration | string | null
The build configuration. Can be:
  • Configuration object
  • Path to configuration file (JSON, YAML, JS, or TS)
  • null to use default configuration from package.json
Example (object):
config: {
  appId: "com.example.app",
  mac: { target: "dmg" }
}
Example (path):
config: "./custom-build-config.yml"

Advanced Options

platformPackagerFactory
((info: Packager, platform: Platform) => PlatformPackager<any>) | null
Factory function to create custom platform packagers. For advanced use cases only.Example:
platformPackagerFactory: (packager, platform) => {
  if (platform === Platform.MAC) {
    return new CustomMacPackager(packager)
  }
  // Return default packagers for other platforms
  return null
}
effectiveOptionComputed
(options: any) => Promise<boolean>
Hook called when effective options are computed. Return false to skip the platform. For internal use.
prepackaged
string | null
The path to a prepackaged app directory. When specified, electron-builder will skip the packaging step and only create distributable formats.Useful for:
  • Packaging already-built apps
  • Separating build and packaging steps
  • Custom build pipelines
Example:
prepackaged: "./dist/mac/My App.app"

Usage Examples

Basic Usage

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

const options = {
  mac: ["dmg"],
  win: ["nsis"],
  linux: ["AppImage"],
  config: {
    appId: "com.example.app",
    productName: "My App"
  }
}

build(options).then(() => {
  console.log("Build complete!")
})

Using Target Map

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

const options = {
  targets: Platform.MAC.createTarget(["dmg", "zip"], Arch.x64, Arch.arm64),
  config: {
    appId: "com.example.app"
  }
}

build(options)

Multiple Platforms

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

const options = {
  targets: createTargets([Platform.MAC, Platform.WINDOWS, Platform.LINUX]),
  config: "./electron-builder.yml"
}

build(options)

Custom Project Directory

const { build } = require("electron-builder")

const options = {
  projectDir: "/path/to/project",
  mac: ["dmg"],
  config: {
    directories: {
      output: "./release"
    }
  }
}

build(options)

Packaging Prebuilt App

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

const options = {
  prepackaged: "./dist/mac/My App.app",
  targets: Platform.MAC.createTarget("dmg")
}

build(options)

TypeScript Example

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

const config: Configuration = {
  appId: "com.example.app",
  productName: "My Application",
  mac: {
    category: "public.app-category.productivity",
    target: ["dmg", "zip"]
  }
}

const options: PackagerOptions = {
  targets: Platform.MAC.createTarget(["dmg", "zip"], Arch.universal),
  projectDir: process.cwd(),
  config
}

async function buildApp() {
  try {
    const artifacts = await build(options)
    console.log("Built artifacts:", artifacts)
  } catch (error) {
    console.error("Build failed:", error)
    process.exit(1)
  }
}

buildApp()

Combined with PublishOptions

When calling build(), you can combine PackagerOptions with PublishOptions:
const { build, Platform } = require("electron-builder")

const options = {
  // PackagerOptions
  targets: Platform.MAC.createTarget(),
  config: {
    appId: "com.example.app",
    publish: {
      provider: "github",
      owner: "my-org",
      repo: "my-repo"
    }
  },
  
  // PublishOptions
  publish: "always" // "onTag", "onTagOrDraft", "always", "never"
}

build(options)

See Also

Build docs developers (and LLMs) love