vue-cli-plugin-electron-builder 打包配置
打包配置文件,根目录下 vue.config.js
module.exports = {
//...
pluginOptions: {
electronBuilder: {
preload: 'src/preload.js',
builderOptions: {
mac: {
icon: 'build/icons/icon.png'
}
}
// Or, for multiple preload files:
// preload: { preload: 'src/preload.js', otherPreload: 'src/preload2.js' }
},
},
//...
};
上例中设置了electron在mac平台下的打包配置项,设置了应用的使用图标
完整的配置项
module.exports = {
pluginOptions: {
electronBuilder: {
builderOptions: {
"appId": "com.example.app",
"productName":"ocr",//项目名,也是生成的安装文件名,即aDemo.exe
"copyright":"Copyright © 2021",//版权信息
"directories":{
"output":"./dist"//输出文件路径
},
"win":{//win相关配置
"icon":"./icon.png",//图标,当前图标在根目录下,注意这里有两个坑
"target": [
{
"target": "nsis",//利用nsis制作安装程序
"arch": [
"x64"//64位
]
}
]
},
"nsis": {
"oneClick": false, // 是否一键安装
"allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
"allowToChangeInstallationDirectory": true, // 允许修改安装目录
"installerIcon": "./shanqis.ico",// 安装图标
"uninstallerIcon": "./shanqis.ico",//卸载图标
"installerHeaderIcon": "./shanqis.ico", // 安装时头部图标
"createDesktopShortcut": true, // 创建桌面图标
"createStartMenuShortcut": true,// 创建开始菜单图标
"shortcutName": "demo", // 图标名称
},
}
}
}
}
另一个打包配置项
对于dll文件的打包和nsis选项进行了配置
module.exports = {
// 第三方插件配置
pluginOptions: {
// vue-cli-plugin-electron-builder 配置
electronBuilder: {
builderOptions: {
// 设置打包之后的应用名称
productName: 'electron-vue-demos',
win: {
icon: 'public/electron-icon/icon.ico',
// 图标路径 windows系统中icon需要256*256的ico格式图片,更换应用图标亦在此处
target: [{
// 打包成一个独立的 exe 安装程序
target: 'nsis',
// 这个意思是打出来32 bit + 64 bit的包,但是要注意:这样打包出来的安装包体积比较大
arch: [
'x64'
// 'ia32'
]
}]
},
dmg: {
contents: [
{
x: 410,
y: 150,
type: 'link',
path: '/Applications'
},
{
x: 130,
y: 150,
type: 'file'
}
]
},
linux: {
// 设置linux的图标
icon: 'resources/ico/icon.png',
target: 'AppImage'
},
mac: {
icon: 'resources/ico/icon.icns'
},
files: ['**/*'],
extraResources: {
// 拷贝dll等静态文件到指定位置,否则打包之后回出现找不大dll的问题
from: 'resources/',
to: './'
},
asar: false,
nsis: {
// 是否一键安装,建议为 false,可以让用户点击下一步、下一步、下一步的形式安装程序,如果为true,当用户双击构建好的程序,自动安装程序并打开,即:一键安装(one-click installer)
oneClick: false,
// 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
allowElevation: true,
// 允许修改安装目录,建议为 true,是否允许用户改变安装目录,默认是不允许
allowToChangeInstallationDirectory: true,
// 安装图标
installerIcon: 'resources/ico/icon.ico',
// 卸载图标
uninstallerIcon: 'resources/ico/icon.ico',
// 安装时头部图标
installerHeaderIcon: 'resources/ico/icon.ico',
// 创建桌面图标
createDesktopShortcut: true,
// 创建开始菜单图标
createStartMenuShortcut: true
}
},
chainWebpackMainProcess: config => {
config.plugin('define').tap(args => {
args[0].IS_ELECTRON = true
return args
})
},
chainWebpackRendererProcess: config => {
config.plugin('define').tap(args => {
args[0].IS_ELECTRON = true
return args
})
}
}
}
}