安装及配置
安装electron包以及electron-builder打包工具
# 安装 electron
cnpm install --save-dev electron
# 安装打包工具
cnpm install electron-builder -D
参考的package.json文件
其中description和author为必填项目
{
"name": "appfile",
"version": "1.0.0",
"description": "appfile",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "electron-builder"
},
"build": {
"appId": "com.test.com",
"win": {
"icon": "./logo.ico",
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
]
},
"nsis": {
"oneClick": false,
"perMachine": true,
"allowToChangeInstallationDirectory": true
}
},
"author": "yxm",
"license": "ISC",
"devDependencies": {
"electron": "^33.0.1",
"electron-builder": "^25.1.8"
}
}
我用的版本为
node版本:20.13.1
npm版本:15.5.2
手动下载依赖
打包时,运行npm run build. 需要从外网下载一些包,下载容易中途断开,断开就要重新来过。可以根据终端提示的地址在浏览器下载,下载后放到对应的文件夹
electron-v33.0.1-win32-x64.zip
C:\Users\yangx\AppData\Local\electron\Cache
这个文件115M,要下载好久。
winCodeSign-2.6.0
C:\Users\yangx\AppData\Local\electron-builder\Cache\winCodeSign\winCodeSign-2.6.0
nsis-3.0.4.1
C:\Users\yangx\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1
nsis-resources-3.4.1
C:\Users\yangx\AppData\Local\electron-builder\Cache\nsis\nsis-resources-3.4.1\plugins
完成