electron-builder介绍
一个完整的解决方案,用于打包和构建适用于macOS、Windows和Linux的可供分发的Electron应用程序,并提供开箱即用的"自动更新"支持。
命令
javascript
Commands:
electron-builder build 构建 [default]
electron-builder install-app-deps 安装app deps
electron-builder node-gyp-rebuild 重新构建自己的本机代码
electron-builder create-self-signed-cert 创建自签名代码签名证书
electron-builder start 在开发中运行应用程序,要使用 electron-webpack
Building:
--mac, -m, -o, --macos 为macOS构建,接受目标列表(see
https://goo.gl/5uHuzj). [array]
--linux, -l 为Linux构建,接受目标列表 (see
https://goo.gl/4vwQad) [array]
--win, -w, --windows 为Windows构建,接受目标列表 (see
https://goo.gl/jYsTEJ) [array]
--x64 为x64构建 [boolean]
--ia32 为ia32构建 [boolean]
--armv7l 为armv7l构建 [boolean]
--arm64 为arm64构建 [boolean]
--dir 构建未打包的目录。有用的测试。 [boolean]
--prepackaged, --pd 预打包应用程序的路径(打包到可分发格式)
--projectDir, --project 项目目录的路径。默认为当前工作目录。
--config, -c electron-builder配置的路径。默认为`electron-builder.yml`(或`json`,或`json 5`,或`js`, see
https://goo.gl/YFRJOM
Publishing:
--publish, -p 发布(到GitHub版本), see
https://goo.gl/tSFycD
[choices: "onTag", "onTagOrDraft", "always", "never", undefined]
Other:
--help 帮助 [boolean]
--version 版本号 [boolean]
适用于macOS、Windows和Linux
electron-builder -mwl
为Linux构建deb和tar.xz
electron-builder --linux deb tar.xz
设置package.json属性foo
到bar
electron-builder -c.extraMetadata.foo=bar
NSIS的配置Unicode选项
electron-builder -c.nsis.unicode=false
nsis简介
NSIS(Nullsoft Scriptable Install System)是一个开源的 Windows 系统下安装程序制作程序。它提供了安装、卸载、系统设置、文件解压缩等功能。NSIS 通过它的脚本语言来描述安装程序的行为和逻辑的。NSIS 的脚本语言和通常的编程语言有类似的结构和语法,但它是为安装程序这类应用所设计的。
配置
-
**appId - 字符串|"undefined"-**应用程序ID
-
**productName- 字符串|"undefined"**应用名称
-
copyright - 字符串|"undefined" 为Copyright © year ${author} 字符串|"undefined"
-
directories - 字符串|"undefined" 元数据目录 | "undefined"
- output - 字符串|"undefined" 默认dist 输出目录
-
nsis - NSIS (Nullsoft Scriptable Install System)制作 windows 安装程序的工具
- oneClick - Boolean 是一键安装
- allowElevation - Boolean 允许请求提升。 如果为false,则用户必须使用提升的权限重 新启动安装程序
- allowToChangeInstallationDirectory - Boolean允许修改安装目录
- installerIcon - String安装图标路径
- uninstallerIcon - String卸载图标
- installerHeaderIcon - String安装时头部图标
- createDesktopShortcut - Boolean 创建桌面图标
- createStartMenuShortcut - Boolean创建开始菜单图标
- shortcutName - String图标名称
- include - String包含的自定义nsis脚本,这个对于构建需求严格得安装过程相当有用
-
win - win系统配置
- icon - String 应用图标路径
- target - Array 是个数组对象 构建目标配置 默认使用当前框架的配
- arch 参数 "arm64" | "armv7l" | "ia32" | "universal" | "x64"
- targe构建的目标类型, 通常window使用nsis
- extraFiles 是一个包含额外文件复制指令的数组。这些文件从指定的源路径复制到目标路径,并且可以根据需要过滤特定文件。
-
mac - mac系统配置
-
icon - String 应用图标路径
-
extraFiles 是一个包含额外文件复制指令的数组。这些文件从指定的源路径复制到目标路径,并且可以根据需要过滤特定文件。
-
**gatekeeperAssess 为false Boolean -**是否让@electron/osx-sign验证签名。
-
**hardenedRuntime 为true Boolean -**您的应用是否必须使用强化运行时进行签名。
**entitlements 字符串|"undefined"-**用于签名应用的授权文件的路径。build/entitlements.mac.plist 如果存在,则将使用(这是建议的设置方式)。MAS权限在mas。这个文件夹在osx-sign的存储库中 请注意,如果未设置正确的权限,您的应用可能会崩溃,例如com.apple.security.cs.allow-jit 例如,在arm 64上构建Electron 20+。请参见从Electron文档对macOS构建进行签名和公证 for more information.
*entitlementsInherit 字符串|"undefined"- 子授权的路径,这些子授权继承了用于对发行版的框架和捆绑包进行签名的安全设置。build/entitlements.mac.inherit.plist 如果存在,将使用(这是一种推荐的设置方式)。请参见这个文件夹在osx-sign的存储库中 例如。此选项仅适用于使用entitlements 提供了
-
extendInfo 任何-额外的条目Info.plist.
-
icon 为build/icon.icns 字符串|"undefined"-应用程序图标的路径
-
-
linux - linux 系统配置
-
extraFiles 是一个包含额外文件复制指令的数组。这些文件从指定的源路径复制到目标路径,并且可以根据需要过滤特定文件。
-
target - 参数 deb 表示构建的目标类型是 Debian 包(
.deb
文件)。这通常用于在 Debian 和 Ubuntu 等基于 Debian 的 Linux 发行版上分发和安装应用。 -
icon - String 应用图标路径
-
-
dmg (仅 macOS):配置生成的 dmg 文件。
contents
:配置 dmg 文件中的内容。icon
:dmg 文件的图标文件路径。background
:自定义 dmg 文件的背景图像
-
pkg
(仅 Linux):配置生成的安装程序。- category应用程序的菜单类别。
- executableName可执行文件的名称
json配置
javascript
"main": "electron/index.js", //入口文件
"scripts": {
"build:win": "electron-builder -w", //打包命令
}
"build": {
"productName":"项目名",//项目名 这也是生成的exe文件的前缀名
"appId": "com.aimooc.包名 ",//appid
"copyright":"xxxx",//版权 信息
"directories": { // 输出文件夹
"output": "dist" // 默认项目根目录下的dist
},
"nsis": {
"oneClick": false, // 是否一键安装
"allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
"allowToChangeInstallationDirectory": true, // 允许修改安装目录
"installerIcon": "./build/icons/aaa.ico", // 安装图标路径
"uninstallerIcon": "./build/icons/bbb.ico", //卸载图标
"installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标
"createDesktopShortcut": true, // 创建桌面图标
"createStartMenuShortcut": true, // 创建开始菜单图标
"shortcutName": "xxxx", // 图标名称
"include": "build/script/installer.nsh", // 包含的自定义nsis脚本,这个对于构建需求严格得安装过程相当有用。
},
// 更新用的配置,主要是为了生成lastest.yaml配置文件
"publish": [
{
"provider": "generic", // 服务器提供商 也可以是GitHub等等
"url": "http://xxxxx/" // 服务器地址
}
],
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns"
},
"win": {
"icon": "build/icons/aims.ico",
"target": [
{
"target": "nsis",
"arch": [ // 打出来32 bit + 64 bit的包(这样的安装包体积较大,建议直接打32的包。
// "x64", // 一般建议去掉
"ia32"
]
}
]
},
"linux": {
"icon": "build/icons"
}
}
yml 配置
productName: nb1
appId: com.jk.app
files:
- icon
- bundle
- electron
nsis:
oneClick: false
allowToChangeInstallationDirectory: true
perMachine: true
win:
icon: icon/im_electron_logo.png
target:
- target: nsis
arch:
- ia32
- x64
解压 app.asar
解压后能看到前端打包内容
安装依赖
npm install -g asar
asar -version
解压
asar extract app.asar ./dist