electron-builder打包环境搭建以及打包过程中的坑
1. 全局安装electron-builder
npm install -g electron-builder
- 1
2. 在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"
]
}
]
}
}
}
3. 开始打包
electron-builder --win
- 1
4. 打包过程中可能遇到的问题
1. 打包时下载electron-v.xxxx.zip文件失败
解决办法:直接在淘宝的文件库下载对应版本和打包平台的文件,下载完成后放在C:\Users\Administrator\AppData\Local\electron\Cache这个目录下
2. 打包时下载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目录下
3. 打包时下载nsis-v.xxx.7z文件失败
下载地址:https://github.com/electron-userland/electron-builder-binaries/releases/download/nsis-3.0.4.1/nsis-3.0.4.1.7z
下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\nsis
4. 打包时下载nsis-resources-v.xxx.7z文件失败
下载地址:https://github.com/electron-userland/electron-builder-binaries/releases/download/nsis-resources-3.4.1/nsis-resources-3.4.1.7z
下载完解压放到C:\Users\Administrator\AppData\Local\electron-builder\Cache\nsis\nsis-resources-3.4.1
第2、3、4步下载的文件如果需要其他版本,直接修改链接中的版本号即可
来源: https://blog.csdn.net/q1059997113/article/details/104273836?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.edu_weight&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.edu_weight