Vue项目打包为exe可安装程序操作步骤

  // Modules to control application life and create native browser window

  const {app, BrowserWindow} = require('electron')

  const path = require('path')

  function createWindow () {

  // Create the browser window.

  const mainWindow = new BrowserWindow({

  webPreferences: {

  preload: path.join(__dirname, 'preload.js')

  },

  resizable: true, //是否支持调整窗口大小

  backgroundColor: '#000000', //窗口背景色

  icon: 'http://www.jb51.net/javascript/dist/favicon.ico' // 左上角图标

  // width: 800, // 指定窗口宽度

  // height: 600, // 指定窗口高度

  // frame: true // 无边框窗口 去掉顶部导航 去掉关闭按钮 最大化最小化按钮

  })

  // and load the index.html of the app.

  // mainWindow.loadFile('index.html') // 原始内容

  mainWindow.loadFile('http://www.jb51.net/javascript/dist/index.html') // 修改后的内容

  mainWindow.setMenu(null) // 隐藏顶部菜单

  mainWindow.webContents.openDevTools() // 打开调试模式

  // 默认窗口最大化

  mainWindow.maximize()

  mainWindow.show()

  }

  // This method will be called when Electron has finished

  // initialization and is ready to create browser windows.

  // Some APIs can only be used after this event occurs.

  app.whenReady().then(() => {

  createWindow()

  app.on('activate', function () {

  // On macOS it's common to re-create a window in the app when the

  // dock icon is clicked and there are no other windows open.

  if (BrowserWindow.getAllWindows().length === 0) createWindow()

  })

  })

  // Quit when all windows are closed, except on macOS. There, it's common

  // for applications and their menu bar to stay active until the user quits

  // explicitly with Cmd + Q.

  app.on('window-all-closed', function () {

  if (process.platform !== 'darwin') app.quit()

  })