如何使用electron將vue項(xiàng)目打包成.exe文件(保姆級(jí)教程)
說明: vue2項(xiàng)目,使用的vue-element-admin框架,用electron打包成.exe文件。
1、新建一個(gè)文件夾,然后右鍵打開終端或者cd到這個(gè)目錄。執(zhí)行下面的命令(最好確認(rèn)一下github網(wǎng)站是否登陸了)。
//將electron官網(wǎng)中的quick-start拉取到本地 git clone https://github.com/electron/electron-quick-start

安裝成功的文件如下顯示:

2.安裝好后,用vscode(其他類似工具)打開,新建終端,前后輸入下面的命令。
//下載項(xiàng)目需要的依賴 npm install //安裝打包.exe所需要的依賴electron-packager、electron npm i electron-packager --save-dev npm i electron --save-dev //運(yùn)行看看是否可以成功 npm run start
如果運(yùn)行成功,會(huì)彈出一個(gè)頁面,如下圖:

3、刪除electron-quick-start文件中的index.html,把自己的項(xiàng)目dist文件放進(jìn)去。

4、打開electron-quick-start文件里的main.js文件,下面是mian.js完整代碼。
重點(diǎn)是: mainWindow.loadFile(“./dist/index.html”) 的修改
// 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: 1024, //自己需要的寬高
height: 960,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
});
// and load the index.html of the app.
mainWindow.loadFile("./dist/index.html");
// Open the DevTools.
mainWindow.webContents.openDevTools(); // 打開調(diào)試工具
}
// 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.5、打開 package.json文件,添加上有關(guān)packager的代碼。
(PS: 如果不需要自動(dòng)匹配dist文件夾下的應(yīng)用圖標(biāo)使用該內(nèi)容
“electron-packager ./ Vite App --platform=win32 --arch=x64 --overwrite”)
"scripts": {
"start": "electron .",
"packager": "electron-packager ./ 你想用的exe名字 --platform=win32 --arch=x64 --icon=./dist/favicon.ico --overwrite"
},
6、終于到了最后一步:npm run packager進(jìn)行打包!打包成功后如下圖
npm run packager

到此這篇關(guān)于用electron將vue項(xiàng)目打包成.exe文件的文章就介紹到這了,更多相關(guān)electron vue打包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue配置electron使用electron-builder進(jìn)行打包的操作方法
- vue3使用Electron打包成exe的方法與打包報(bào)錯(cuò)解決
- 使用electron打包Vue前端項(xiàng)目的詳細(xì)流程
- 解決electron打包vue-element-admin項(xiàng)目頁面無法跳轉(zhuǎn)的問題小結(jié)
- vue項(xiàng)目使用electron進(jìn)行打包操作的全過程
- 手把手教你使用electron將vue項(xiàng)目打包成exe
- 關(guān)于electron-vue打包后運(yùn)行白屏的解決方案
- vue項(xiàng)目打包成桌面快捷方式(electron)的方法
- 用electron打包vue項(xiàng)目中的報(bào)錯(cuò)問題及解決
- vue 項(xiàng)目集成 electron 和 electron 打包及環(huán)境配置方法
相關(guān)文章
解決vue的 v-for 循環(huán)中圖片加載路徑問題
今天小編就為大家分享一篇解決vue的 v-for 循環(huán)中圖片加載路徑問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09
vue3?使用?vue3-video-play實(shí)現(xiàn)在線視頻播放
這篇文章主要介紹了vue3?使用?vue3-video-play?進(jìn)行在線視頻播放,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06
element-ui封裝一個(gè)Table模板組件的示例
這篇文章主要介紹了element-ui封裝一個(gè)Table模板組件的示例,幫助大家更好的理解和學(xué)習(xí)vue框架的使用,感興趣的朋友可以了解下2021-01-01
關(guān)于axios配置多個(gè)請(qǐng)求地址(打包后可通過配置文件修改)
這篇文章主要介紹了關(guān)于axios配置多個(gè)請(qǐng)求地址(打包后可通過配置文件修改),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
詳解vuelidate 對(duì)于vueJs2.0的驗(yàn)證解決方案
本篇文章主要介紹了vuelidate 對(duì)于vueJs2.0的驗(yàn)證解決方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03

