02.electron打包操作(electron-builder)
安装依赖
yarn add --save-dev electron-builder
1
打包命令
#打包到win64
electron-builder --win --x64
1
2
2
都配置在package.json
文件
# build常用配置项
{
"build": {
"productName": "项目名称",
"appId": "appid",
"publish":[], // 发行相关配置
"win":{}, // window下相关配置
"nsis":{}, // nsis打包相关配置
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# win相关配置
{
"win":{
"target": ["nsis"], // 打包成安装文件
"icon": "./static/login.png", // 设置图标
}
}
1
2
3
4
5
6
2
3
4
5
6
# nsis常用配置项
{
"oneClick": true, // 默认true, 是否按所有用户(每台计算机)
"allowToChangeInstallationDirectory": true, // 默认false,true:用户可以选择修改安装目录
"createDesktopShortcut": true, // 创建桌面快捷方式
"runAfterFinish": true, // 安装完成后运行软件
}
1
2
3
4
5
6
2
3
4
5
6
# Vue2打包
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
...
pluginOptions: {
electronBuilder: {
nodeIntegration: true,
builderOptions: {
nsis: {
oneClick: false,
allowToChangeInstallationDirectory: true,
createDesktopShortcut:true,
runAfterFinish:true
},
// build配置在此处
"productName": "眼健康小屋",
"appId": "health.jsyufang.com",
"publish": [
{
provider: "generic",
url: 'https://jn-ding-talk.oss-cn-beijing.aliyuncs.com/'
}
],
"win": {
"icon": "./src/assets/health-hut-256.png"
}
}
},
},
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
上次更新: 2023/09/22, 16:54:32