1.安装打包依赖,调整打包命令
npm install electron-builder -D
2.安装完成后,在 package json 中,配置 build 命令
"build": "vite build && electron-builder",
3.electron/index.js修改 win.loadURL 中的路径参数,判断下当前是生产环境,还是开发环境
![](https://i-blog.csdnimg.cn/blog_migrate/ae6d99a412e0b2283d35dc9a31a6f95e.png)
4.修改 package.json,增加打包相关配置
"build": {
"appId": "com.electron.desktop",
"productName": "electron",
"asar": false,
"copyright": "Copyright © 2022 electron",
"directories": {
"output": "release/"
},
"files": [
"dist"
],
"mac": {
"artifactName": "${productName}_${version}.${ext}",
"target": [
"dmg"
]
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
],
"artifactName": "${productName}_${version}.${ext}"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
},
"publish": [
{
"provider": "generic",
"url": "http://127.0.0.1:8080"
}
],
"releaseInfo": {
"releaseNotes": "版本更新的具体内容"
}
}
5.执行打包命令
npm run build