Home > Article > Web Front-end > Detailed introduction to electron-builder packaging
This article brings you a detailed introduction to electron-builder packaging. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
When developing electron client programs, packaging is an unavoidable problem. Let me share some insights based on my experience at work and my current understanding of electron-builder
.
Basic concepts
Definition of official website
A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out of the box.This article about the basic parts of electron and electron-builder has been skipped. If you are interested, you can read this article
How to use
The use and configuration of builder is very simple
There are two ways to configure builder
Configure and use it directly in package.json (more commonly used, we will focus on this below)
Specify the electron-builder.yml file
The demo address will be given at the end of the article (electron in the demo project uses version V2.0.7, and currently the higher version is version 2.0.8).
The following is a simple annotated configuration in package.js
Basic configuration
"build": { // 这里是electron-builder的配置 "productName":"xxxx",//项目名 这也是生成的exe文件的前缀名 "appId": "com.xxx.xxxxx",//包名 "copyright":"xxxx",//版权 信息 "directories": { // 输出文件夹 "output": "build" }, // windows相关的配置 "win": { "icon": "xxx/icon.ico"//图标路径 } }
In the configuration file After adding the above files, you can package it into a simple folder. The folder is definitely not what we want. Next we will continue to talk about other configurations.
Packaging target configuration
If you want to package it into an installation program, we have two ways,
Use the NSIS tool to package our folder again and package it into exe
Package it directly into exe through nsis of electron-builder. The configuration is as follows
"win": { // 更改build下选项 "icon": "build/icons/aims.ico", "target": [ { "target": "nsis" // 我们要的目标安装包 } ] },
Other platform configuration
"dmg": { // macOSdmg "contents": [ ... ] }, "mac": { // mac "icon": "build/icons/icon.icns" }, "linux": { // linux "icon": "build/icons" }
##nsis configuration
"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脚本 这个对于构建需求严格得安装过程相当有用。 "script" : "build/script/installer.nsh" // NSIS脚本的路径,用于自定义安装程序。 默认为build / installer.nsi },About
include and
script Which one to choose?
include configuration. If you need a cool installation process , it is recommended to use
script for complete customization.
NSIS is very powerful for processing installation packages. But it is no easier to learn than a high-level language. The secrets need to be explored by yourselves
electron-builder --ia32 // 32位 electron-builder // 64位(默认)Configuration in nsis
"win": { "icon": "build/icons/aims.ico", "target": [ { "target": "nsis", "arch": [ // 这个意思是打出来32 bit + 64 bit的包,但是要注意:这样打包出来的安装包体积比较大,所以建议直接打32的安装包。 "x64", "ia32" ] } ] }
lastest.yamlconfiguration file
"publish": [ { "provider": "generic", // 服务器提供商 也可以是GitHub等等 "url": "http://xxxxx/" // 服务器地址 } ],
Complete configuration
Basically available complete configuration"build": { "productName":"xxxx",//项目名 这也是生成的exe文件的前缀名 "appId": "com.leon.xxxxx",//包名 "copyright":"xxxx",//版权 信息 "directories": { // 输出文件夹 "output": "build" }, "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脚本 }, "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": [ "ia32" ] } ] }, "linux": { "icon": "build/icons" } }
Command line parameters (CLI)
Commands(command ):electron-builder build 构建命名 [default] electron-builder install-app-deps 下载app依赖 electron-builder node-gyp-rebuild 重建自己的本机代码 electron-builder create-self-signed-cert 为Windows应用程序创建自签名代码签名证书 electron-builder start 使用electronic-webpack在开发模式下运行应用程序(须臾要electron-webpack模块支持)Building(Building parameters):
--mac, -m, -o, --macos Build for macOS, [array] --linux, -l Build for Linux [array] --win, -w, --windows Build for Windows [array] --x64 Build for x64 (64位安装包) [boolean] --ia32 Build for ia32(32位安装包) [boolean] --armv7l Build for armv7l [boolean] --arm64 Build for arm64 [boolean] --dir Build unpacked dir. Useful to test. [boolean] --prepackaged, --pd 预打包应用程序的路径(以可分发的格式打包) --projectDir, --project 项目目录的路径。 默认为当前工作目录。 --config, -c 配置文件路径。 默认为`electron-builder.yml`(或`js`,或`js5`)Publishing(Publishing):
--publish, -p 发布到GitHub Releases [choices: "onTag", "onTagOrDraft", "always", "never", undefined]
Deprecated(Deprecated ):
--draft 请改为在GitHub发布选项中设置releaseType [boolean] --prerelease 请改为在GitHub发布选项中设置releaseType [boolean] --platform 目标平台 (请更改为选项 --mac, --win or --linux) [choices: "mac", "win", "linux", "darwin", "win32", "all", undefined] --arch 目标arch (请更改为选项 --x64 or --ia32) [choices: "ia32", "x64", "armv7l", "arm64", "all", undefined]Other(other):
--help Show help [boolean] --version Show version number [boolean]Examples(examples):
electron-builder -mwl 为macOS,Windows和Linux构建(同时构建) electron-builder --linux deb tar.xz 为Linux构建deb和tar.xz electron-builder -c.extraMetadata.foo=bar 将package.js属性`foo`设置为`bar` electron-builder --config.nsis.unicode=false 为NSIS配置unicode选项TargetConfiguration(build target configuration):
target: String - 目标名称,例如snap. arch “x64” | “ia32” | “armv7l” | “arm64”> | “x64” | “ia32” | “armv7l” | “arm64” -arch支持列表
Summary
electron-builder is a simple and powerful library. Anyway, I’m very impressedThe above is the detailed content of Detailed introduction to electron-builder packaging. For more information, please follow other related articles on the PHP Chinese website!