LinuxCommandLibrary

electron-packager

Package Electron apps for distribution

TLDR

Package an application for the current architecture and platform

$ electron-packager "[path/to/app]" "[app_name]"
copy

Package an application for all architectures and platforms
$ electron-packager "[path/to/app]" "[app_name]" --all
copy

Package an application for 64-bit Linux
$ electron-packager "[path/to/app]" "[app_name]" --platform="[linux]" --arch="[x64]"
copy

Package an application for ARM macOS
$ electron-packager "[path/to/app]" "[app_name]" --platform="[darwin]" --arch="[arm64]"
copy

SYNOPSIS

electron-packager <source_directory> <app_name> [options]
Example: electron-packager . my-app --platform=win32 --arch=x64 --out=release-builds

PARAMETERS

source_directory
    Path to the Electron app's source code.

app_name
    Name of the application.

--platform=
    Target OS platform (e.g., win32, darwin, linux).

--arch=
    Target CPU architecture (e.g., x64, ia32, arm64).

--out=


    Directory to place the packaged application.

--overwrite
    Overwrite existing output directory if it exists.

--icon=
    Path to the application icon file.

--prune
    Prune extraneous node_modules files.

--version
    Display electron-packager version.

--help
    Display help information.

--electron-version=
    Specify the Electron runtime version to use.

--asar
    Package application code into an ASAR archive.

--ignore=
    Patterns of files/directories to exclude from packaging.

--executable-name=
    Sets the name of the main executable file.

DESCRIPTION

electron-packager is a command-line tool and Node.js library that allows you to easily bundle your Electron application into OS-specific executables (e.g., .app for macOS, .exe for Windows, Linux binaries). It takes your Electron app's source directory, downloads the necessary Electron prebuilt binaries for the specified platform and architecture, and then packages your application's code into a distributable format. This automates the complex process of preparing an Electron app for release, including handling dependencies, creating an application bundle structure, and optionally setting icons. It is widely used for its simplicity and direct approach to packaging Electron applications across different operating systems, making it a foundational tool for Electron developers.

CAVEATS

Requires Node.js and npm to be installed. Downloads Electron binaries for each specified platform/architecture, which can be large. The output directory can be quite substantial in size. electron-packager handles packaging the application but does not create installers (like MSI for Windows or DMG for macOS); additional tools are needed for this. Cross-compilation from one OS to another can sometimes require specific dependencies or configurations for native modules.

TYPICAL WORKFLOW

Users typically run electron-packager after developing their Electron application and ensuring all dependencies are installed. The command will then generate a platform-specific directory containing the Electron runtime, the application's source code, and its node_modules. This output is then ready for direct distribution or for further processing by installer-creation tools.

CONFIGURATION

While primarily a command-line tool, electron-packager options can also be specified programmatically when used as a Node.js library, or conveniently defined within a package.json script for consistent builds.

HISTORY

electron-packager emerged as one of the earliest and most straightforward tools for packaging Electron applications shortly after the framework (originally Atom Shell) gained widespread popularity. It provides a direct, programmatic approach to bundling Electron apps, contrasting with more opinionated and feature-rich alternatives like electron-builder which often came later. Its development has focused on reliability and cross-platform compatibility for basic packaging needs, making it a foundational tool for early Electron developers.

SEE ALSO

npm, electron, electron-builder

Copied to clipboard