近期项目需求,把网页(基于vue)打包成exe桌面应用,在网上找到了electron;
这里说说我对electron-builder的使用心得
electron打包exe程序主要有两种方法:
1、electron-packager:初学者入门demo传送门
2、electron-builder:稍微复杂一丢丢,需要配置文件
#######
先将vue项目打包 npm run build 得到dist文件夹(我这里是web文件夹)
build文件夹下添加文件 electron.js
electron.js
// Modules to control application life and create native browser window
const {
app, BrowserWindow, Menu } = require('electron')
const path = require('path')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
// width: 1920,
// height: 1000,
show: false,
webPreferences: {
nodeIntegration:true,
preload: path.join(__dirname, '../web/preload.js')
}
})
// 默认全屏
mainWindow.maximize()
mainWindow.show()
// and load the index.html of the app.
// 要加载的页面,打包后的web/index.html
mainWindow.