当前位置: 首页 > news >正文

vue打包的dist文件,再使用eletron打包为exe

1.下载eletron demo

demo

2.npm install

2.1如遇443,使用eletron镜像专用源,参考链接
[eletron]RequestError: connect ETIMEDOUT 20.205.243.166:443,为eletron设置专用源。

3.在electron-quick-start-main下粘贴dist

在这里插入图片描述

4.再粘贴static/logo.ico(大小256*256[必须])

用来修改软件图标,大小必须256*256

5.再修改main.js

5.1改变了index.html路径

  mainWindow.loadFile('dist/index.html')

5.2创建系统托盘并改变系统托盘图标
5.3内容如下:

// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const path = require('node:path')function createWindow () {// Create the browser window.const mainWindow = new BrowserWindow({width: 800,height: 600,webPreferences: {preload: path.join(__dirname, 'preload.js')}})// and load the index.html of the app.// mainWindow.loadFile('index.html')mainWindow.loadFile('dist/index.html')// 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.// 创建系统托盘(和托盘事件)和改变.exe文件图片为logo.ico---------------开始
const { Tray, Menu } = require('electron');
let tray = null;app.on('ready', () => {// 使用你指定的图标const iconPath = path.join(__dirname, 'static', 'logo.ico'); // 获取绝对路径// 创建系统托盘tray = new Tray(iconPath);// 创建上下文菜单const contextMenu = Menu.buildFromTemplate([{ label: 'Item 1', click: () => { console.log('Item 1 clicked'); } },{ label: 'Item 2', click: () => { console.log('Item 2 clicked'); } },{ type: 'separator' },{ label: 'Quit', click: () => { app.quit(); } }]);// 设置托盘的上下文菜单tray.setToolTip('This is my application.');tray.setContextMenu(contextMenu);// 可以添加托盘的点击事件tray.on('click', () => {console.log('Tray icon clicked');// 这里可以打开窗口或其他操作});
});// 处理应用退出时的操作
app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});
// 创建系统托盘和改变.exe文件图片为logo.ico---------------结束

6.最后进行打包,在package.json,添加打包命令

6.1打包命令

  "scripts": {"start": "electron .","make-win": "npx electron-packager ./ custom-package-name --platform=win32 --arch=x64 --out=jimmy-dist --overwrite --icon=./static/logo.ico"},

6.2完整package.json

{"name": "electron-quick-start","version": "1.0.0","description": "A minimal Electron application","main": "main.js","scripts": {"start": "electron .","make-win": "npx electron-packager ./ custom-package-name --platform=win32 --arch=x64 --out=jimmy-dist --overwrite --icon=./static/logo.ico"},"repository": "https://github.com/electron/electron-quick-start","keywords": ["Electron","quick","start","tutorial","demo"],"author": "GitHub","license": "CC0-1.0","devDependencies": {"electron": "^33.0.2"}
}

http://www.mrgr.cn/news/61709.html

相关文章:

  • 【常用动画方式】transition\animation\定时器setInterval+setTimeout\requestAnimationFrame
  • 「C/C++」C++ 设计模式 之 单例模式(Singleton)
  • 双指针——对撞指针与左右指针
  • 【flink】之kafka到kafka
  • 代码随想录 | Day35 | 动态规划 :最小花费爬楼梯不同路径不同路径II
  • Bash、sh 和 Shell都弄混了?
  • GitHub Copilot 转型采用多模型策略,支持 Claude 3.5 和 Gemini
  • Cesium中遇到 materialProperty.getType is not a function
  • 2024 FinTechathon 校园行:助力高校学生探索金融科技创新
  • PHP爬虫的奇幻之旅:如何用代码“偷窥”京东商品的SKU信息
  • 使用Python实现一个简单的HTTP服务器:返回当前时间
  • 【机器学习】音乐与AI的交响:机器学习在音乐产业中的应用
  • Ubuntu 20.04 安装 OpenCV 和 OpenCV_contrib 教程
  • CodeS:构建用于文本到 SQL 的开源语言模型
  • 戴尔 Inspiron 14 5418 (11代)安装win10 ltsc lot 企业版
  • 这些人真TM野路子!用AI赚了百万
  • 手动写一个new
  • error LNK2001: 无法解析的外部符号 “public:xxxxxx“
  • vite5 打包项目兼容ie和低版本chrome
  • 基于openEuler22.03的rpcapd抓包机安装
  • 基于Springboot+微信小程序的房产交易租赁服务平台设计与实现 (含源码数据库)
  • 结合 Spring Boot Native 和 Spring Boot 构建高性能服务器架构
  • 【RUOYI3.8.8】框架参考笔记
  • 【计算机网络 - 基础问题】每日 3 题(六十)
  • 【C++】踏上C++学习之旅(四):细说“内联函数“的那些事
  • 【C++】智能指针的奥秘:深度解析std::unique_ptr与std::shared_ptr