vue项目 通过Electron打包成exe

该文章提供了一个Vue+Electron项目打包成exe程序的教程,包括使用镜像加速npminstallelectron的过程,配置main.js以创建和管理应用窗口,以及调整package.json以实现用户选择安装目录的功能。文章强调了在打包过程中可能遇到的慢速问题,并提供了详细步骤来避免常见错误。

首先,说明一下,网上到处都是各种教程,各种抄袭。我搞了三个小时很不容易,只是做个总结,内容全是转载。其次npm i electron很慢,建议镜像,镜像也得个5min左右,做好心理准备,不是报错,只是慢。

第一步:看这个(但是不要复制里面的main.js和package.json文件)

vue+electron将项目打包为exe程序---成功跨过所有坑,完美打包_suoh's Blog的博客-优快云博客_vue 项目 打包 electron

第二步:main.js配置,直接复制,没有问题 (重点在中文注释,看你自己想不想要)

// 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({
    width: 1366,
    height: 768,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
    },
  });

  // and load the index.html of the app.
  mainWindow.loadFile("index.html");
  //重点在这,这段代码可以删除菜单栏
  mainWindow.setMenu(null);

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

// 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();
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

第三步:配置package.json

Electron打包配置 + package.json的常用配置项及其用法解析_神奇小邓的博客-优快云博客_electron package.json

 第四步:package.json配置 用户选择安装目录的配置

Electron打包vue项目 用户可选择安装目录_小树枝.的博客-优快云博客_electron 选择目录

electron-builder 设置用户可以自己选择安装目录_豪先生5的博客-优快云博客_"// \"electron-devtools-installer\": \"^3.1.0\", /

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值