electron-builder npm versiondownloads per month

electron-builder是一个完整的解决方案,对于macos、windows、linux下的electron app,它可以提供打包及构建的相关功能。同时,它还提供开箱即用的“自动更新”功能支持。

  • NPM 包管理:
    • 原生应用依赖 编译 (包括 Yarn 支持).
    • Development dependencies are never included. You don't need to ignore them explicitly.
  • Code Signing on a CI server or development machine.
  • Auto Update ready application packaging.
  • 众多目标格式:
    • 所有平台: 7z, zip, tar.xz, tar.lz, tar.gz, tar.bz2, dir (unpacked directory).
    • macOS: dmg, pkg, mas, mas-dev.
    • Linux: AppImage, snap, debian package (deb), rpm, freebsd, pacman, p5p, apk.
    • Windows: nsis (Installer), nsis-web (Web installer), portable (portable app without installation), AppX (Windows Store), Squirrel.Windows.
  • Two package.json structure is supported, but you are not forced to use it even if you have native production dependencies.
  • Build version management.
  • Publishing artifacts to GitHub Releases, Amazon S3, DigitalOcean Spaces and Bintray.
  • Pack in a distributable format already packaged app.
  • 独立的 构建步骤.
  • Build and publish in parallel, using hard links on CI server to reduce IO and disk space usage.
  • electron-compile support (compile for release-time on the fly on build).
  • Docker images to build Electron app for Linux or Windows on any platform.
问题 回答
我想要配置 electron-builder” 查看选项
“我有一个问题” 提交一个issue 或者 参与讨论
“我发现了一个bug” 提交一个issue
“我想要捐钱” 捐献

真实项目实例 — onshape-desktop-shell.


强烈推荐 您使用 Yarn ,来取代npm。

yarn add electron-builder --dev

Platform specific 7zip-bin-* packages are optionalDependencies, which may require manual install if you have npm configured to not install optional deps by default.



electron-webpack-quick-start is a recommended way to create a new Electron application.

  1. Specify the standard fields in the application package.jsonname, description, version and author.

  2. 在下面的package.json文件中,如下指明 构建 配置:

    "build": {
       "appId": "your.id",
       "mac": {
         "category": "your.app.category.type"

    参见 所有选项

  3. 添加 图标.

  4. 添加 scripts 内容到开发版的package.json中:

    然后你就可以运行命令 yarn dist (to package in a distributable format (e.g. dmg, windows installer, deb package)) 或者运行命令 yarn pack (only generates the package directory without really packaging it. This is useful for testing purposes).

    为了确保你的原生依赖总是搭配electron的版本号,最简单的的办法就是添加如下命令: "postinstall": "electron-builder install-app-deps" 到你的 package.json文件之中。

    "scripts": {
      "pack": "electron-builder --dir",
      "dist": "electron-builder"
  1. 如果你的应用里面,包含有自己的原生addon (并不是依赖项),那么请设置 nodeGypRebuildtrue

  2. 如果你不是 macOS 10.12+ 系统的话,您需要安装 必须的系统包。请注意, 默认情况下,所有的文件都会被打包到asar压缩包中。对于一个将要马上投入生产的app,你应该对你的应用进行签名。参见 哪里可以购买签名证书.


请参见 node_modules/electron-builder/out/index.d.ts。为 TypeScript 提供了 Typings。

"use strict"

const builder = require("electron-builder")
const Platform = builder.Platform

// Promise is returned
  targets: Platform.MAC.createTarget(),
  config: {
   "//": "build options, see https://goo.gl/ZhRfla"
  .then(() => {
    // handle result
  .catch((error) => {
    // handle error


您可以用electron-builder只打包下面的某种格式。 AppImage, Snaps, Debian package, NSIS, macOS installer component package (pkg) 以及其他发行格式。.

./node_modules/.bin/build --prepackaged <packed dir>

--projectDir (指向project目录) 选项也是很有用的。


Slack的electron-builder 频道 (请使用 threads). 无需注册,公共 打包 .