Vue項(xiàng)目打包為exe可安裝程序操作步驟
前言
使用 Electron 和 Inno Setup 將 vue項(xiàng)目打包為 exe 可安裝程序
1 )、Electron 下載安裝方式
- 官網(wǎng)地址
- git倉(cāng)庫(kù)下載地址
git clone https://github.com/electron/electron-quick-start cd electron-quick-start npm install npm start
運(yùn)行成功后界面

2 ) 、 Inno Setup 下載安裝方式
無腦下一步即可
- 官網(wǎng)地址
- 各大應(yīng)用商城下載(如:電腦管家、360等)
操作步驟
一、修改需要打包為 exe 項(xiàng)目的 vite.config.js 或 vue.config.js 配置文件
// vite.config.js
export default defineConfig({
base: "./",
})
或
// vue.config.js
module.exports = {
publicPath: "./",
} 路徑必須修改為 "./" ,不然可能造成頁(yè)面空白或加載失敗的情況
二、 在不熟悉 Electron 在 Vue 項(xiàng)目中配置 的情況下建議在 electron-quick-start ( 官方demo,前言中clone 的項(xiàng)目)中安裝打包需要的依賴。 (在原vue項(xiàng)目中的操作可自行百度)
npm install electron-packager --save-dev
三、刪除 electron-quick-start 根目錄下的 index.html 文件 四、在 electron-quick-start 項(xiàng)目中 找到 main.js 文件修改其配置

更多配置請(qǐng)移步 Electron官網(wǎng) 查看
mainWindow.loadFile('./dist/index.html') 為vue項(xiàng)目打包后的 index.html 所在地址,指向必須正確否則無法正確展示頁(yè)面?。。?/p>
代碼如下:
// 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, //是否支持調(diào)整窗口大小
backgroundColor: '#000000', //窗口背景色
icon: './dist/favicon.ico' // 左上角圖標(biāo)
// width: 800, // 指定窗口寬度
// height: 600, // 指定窗口高度
// frame: true // 無邊框窗口 去掉頂部導(dǎo)航 去掉關(guān)閉按鈕 最大化最小化按鈕
})
// and load the index.html of the app.
// mainWindow.loadFile('index.html') // 原始內(nèi)容
mainWindow.loadFile('./dist/index.html') // 修改后的內(nèi)容
mainWindow.setMenu(null) // 隱藏頂部菜單
mainWindow.webContents.openDevTools() // 打開調(diào)試模式
// 默認(rèn)窗口最大化
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()
})五、在 electron-quick-start 項(xiàng)目 package.json 配置文件中,scripts 下添加 packager 指令
"scripts": {
"start": "electron .",
"packager": "electron-packager ./ App --platform=win32 --arch=x64 --electron-version=19.0.6 --icon=logo.ico --overwrite"
}
--icon=logo.ico 為打包后 exe 文件的圖標(biāo),logo.ico 是 .ico 文件地址與 node_modules 平級(jí)可忽略路徑,否則需要表明路徑如:(./dist/logo.ico)
可能遇到的坑:
rcedit.exe failed with exit code 1. Reserved header is not 0 or image type is not icon for xxxxxxxx
解決方法:下載生成ico工具:https://icofx.ro/;下載后將所需的文件保存為 ico 后綴即可。
六、打包原 Vue 項(xiàng)目,將打包后生成的 dist 文件夾放在 electron-quick-start 項(xiàng)目中與node_modules 平級(jí)即可
如果原 Vue 項(xiàng)目中使用了反向代理處理跨域問題的話,那么在打包前須注釋掉代理方法,否則的話會(huì)無法訪問接口?。?!
七、輸入打包命令 npm run packager 執(zhí)行成功后,electron-quick-start 項(xiàng)目中會(huì)出現(xiàn)一個(gè) App-win32-x64 的文件夾,該文件夾內(nèi) App.exe 即為項(xiàng)目的啟動(dòng)文件
npm run packager

八、至此 exe 打包已完成 ?????? 接下來使用 Inno Setup(前言中提到過)工具生成安裝程序包 新建文件

或者使用快捷鍵 Ctrl + N 新建

下一步(Next):填寫應(yīng)用基本信息(名稱、版本、發(fā)布者 和 官網(wǎng))

下一步(Next):填寫應(yīng)用文件夾信息

下一步(Next):選擇生成安裝程序的文件

下一步(Next):為程序創(chuàng)建快捷方式

下一步(Next):指定安裝程序在安裝期間應(yīng)顯示的文件(可不填,直接下一步即可)

下一步(Next):選擇安裝模式(直接下一步即可,默認(rèn)為:管理員安裝模式(為所有用戶安裝))

下一步(Next):選擇語(yǔ)言(直接下一步即可)

下一步(Next):編譯相關(guān)配置

下一步(Next):是否應(yīng)使用 Inno Setup 預(yù)處理器(直接下一步即可)

Finish

是

是(選擇 .iss文件 保存位置)

??????至此等待打包完成即可??????
總結(jié)
到此這篇關(guān)于Vue項(xiàng)目打包為exe可安裝程序操作步驟的文章就介紹到這了,更多相關(guān)Vue打包exe可安裝程序內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決項(xiàng)目vite1.0升級(jí)到2.0打包遇到Some chunks are larger問題
本文主要介紹了解決項(xiàng)目vite1.0升級(jí)到2.0打包遇到Some chunks are larger問題,文中根據(jù)實(shí)例編碼詳細(xì)介紹的十分詳盡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
解決vue select當(dāng)前value沒有更新到vue對(duì)象屬性的問題
今天小編就為大家分享一篇解決vue select當(dāng)前value沒有更新到vue對(duì)象屬性的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08
Vue 3 響應(yīng)式系統(tǒng)中ref 在 reactive 中的自動(dòng)解包行為
Vue3中,ref與reactive配合使用時(shí)會(huì)自動(dòng)解包,使代碼更簡(jiǎn)潔,響應(yīng)式系統(tǒng)更智能,替換ref會(huì)斷開舊連接,淺層reactive/shallowRef不觸發(fā)解包,但是需注意區(qū)分,下面通過示例給大家介紹Vue3響應(yīng)式探秘:ref 在reactive中的自動(dòng)解包行為解析,感興趣的朋友一起看看吧2025-07-07
vue iview的菜單組件Mune 點(diǎn)擊不高亮的解決方案
今天小編就為大家分享一篇vue iview的菜單組件Mune 點(diǎn)擊不高亮的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue3中利用Export2Excel將數(shù)據(jù)導(dǎo)出為excel表格
這篇文章主要給大家介紹了關(guān)于vue3中利用Export2Excel將數(shù)據(jù)導(dǎo)出為excel表格的相關(guān)資料,最近項(xiàng)目需要前端來導(dǎo)出Excel操作,所以給大家總結(jié)下,需要的朋友可以參考下2023-09-09
手把手教你使用electron將vue項(xiàng)目打包成exe
Electron相當(dāng)于一個(gè)瀏覽器的外殼,可以把現(xiàn)有的vue程序嵌入到殼里面,下面這篇文章主要給大家介紹了關(guān)于如何使用electron將vue項(xiàng)目打包成exe的相關(guān)資料,需要的朋友可以參考下2023-01-01

