使用electron-buil将vue打包成exe并生成安装包
程序员文章站
2022-06-04 16:49:56
...
- 将vue进行打包
npm run build
- 安装electron-build和安装electron
在使用electron-build的时候必须安装electron- 安装命令
npm i yarn -g //需要先安装yarn,然后再进行安装 yarn add electron-builder --dev
- 在package.json里面添加一下内容
{ "main": "main.js", "devDependencies": { "electron-builder": "^22.10.5" }, "name": "wuzi", "version": "0.1.0", "build": { "productName":"Electron_Test", "appId": "aaaa", "copyright":"aaa", "directories": { "output": "build" }, "nsis": { "oneClick": false, "allowElevation": true, "allowToChangeInstallationDirectory": true, "createDesktopShortcut": true, "createStartMenuShortcut": true, "shortcutName": "xxxx" } } }
- 在当前路径新建一个main.js文件(直接从electron官方拉下来的)
const { app, BrowserWindow } = require('electron') const path = require('path') function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') } }) win.loadFile('./dist/index.html') } app.whenReady().then(() => { createWindow() app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } }) }) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } })
- 执行electron-builder就好了,这是我们在同级目录里面找到安装包了
上一篇: python笔试题汇总
下一篇: Java笔试题汇总