electron-builder
electron-builder
electron-builder是一个完整的解决方案,对于macos、windows、linux下的electron app,它可以提供打包及构建的相关功能。同时,它还提供开箱即用的“自动更新”功能支持。
- NPM 包管理:
- 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 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 — A bare minimum project structure to get started developing with electron-webpack. Recommended.
- electron-react-boilerplate A boilerplate for scalable cross-platform desktop apps.
- electron-react-redux-boilerplate A minimal boilerplate to get started with Electron, React and Redux.
- electron-boilerplate A minimalistic yet comprehensive boilerplate application.
快速设置向导
electron-webpack-quick-start is a recommended way to create a new Electron application.
Specify the standard fields in the application
package.json
— name,description
,version
and author.在下面的
package.json
文件中,如下指明 构建 配置:"build": { "appId": "your.id", "mac": { "category": "your.app.category.type" } }
参见 所有选项。
添加 图标.
添加 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"
}
如果你的应用里面,包含有自己的原生addon (并不是依赖项),那么请设置 nodeGypRebuild为
true
。如果你不是 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
builder.build({
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). 无需注册,公共 打包 .
相关npm包集合
- electron-packager
- electron-builder
- electron-updater
- electron-download
- electron-apps
- electron-to-chromium
- awesome-electron
- electron-debug
- electron-rebuild