本文档在electron v8.0.0和electron-builder v22.3.2环境下编写,其他版本的环境可能会略有差异
全局安装electron-builder
npm install -g electron-builder
在package.json文件中增加打包的配置
完整配置项文档地址:https://www.electron.build/configuration/configuration
{
"build": {
"productName":"Electron_Test",
"appId": "xxxx",
"copyright":"xxxx",
"directories": {
"output": "build"
},
"nsis": {
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "./build/icons/aaa.ico",
"uninstallerIcon": "./build/icons/aaa.ico",
"installerHeaderIcon": "./build/icons/aaa.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "xxxx"
},
"publish": [
{
"provider": "generic",
"url": "http://xxxxx/"
}
],
"files": [
"./main.js",
"./dist/**",
"./package.json",
"./preload.js"
],
"win": {
"icon": "build/icons/aaa.ico",
"target": [
{
"target": "nsis",
"arch": [
"ia32"
]
}
]
}
}
}
开始打包
electron-builder --win
打包过程中可能遇到的问题
打包时下载electron-v.xxxx.zip文件失败
解决办法:直接在淘宝的文件库下载对应版本和打包平台的文件,下载完成后放在C:\Users\Administrator\AppData\Local\electron\Cache这个目录下
打包时下载winCodeSign-v.xxx.7z文件失败
下载地址:https://github.com/electron-userland/electron-builder-binaries/releases/download/winCodeSign-2.5.0/winCodeSign-2.5.0.7z
下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\winCodeSign目录下
下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\nsis
下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\nsis\nsis-resources-3.4.1
第2、3、4步下载的文件如果需要其他版本,直接修改链接中的版本号即可