最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何使用electron將vue項(xiàng)目打包成.exe文件(保姆級教程)

 更新時(shí)間:2024年03月16日 11:24:59   作者:小小黑007  
本文給大家介紹如何使用electron將vue項(xiàng)目打包成.exe文件,大家要注意一下vue2項(xiàng)目,使用的vue-element-admin框架,用electron打包成.exe文件,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧

說明: 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)行成功,會彈出一個(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: 如果不需要自動匹配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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

内丘县| 呼伦贝尔市| 日土县| 合作市| 邹城市| 铜陵市| 遂宁市| 玛曲县| 綦江县| 乌鲁木齐县| 弥渡县| 阿合奇县| 蛟河市| 普兰店市| 皋兰县| 威信县| 黑水县| 阿坝县| 磴口县| 英超| 青龙| 新宾| 林州市| 即墨市| 郑州市| 太和县| 苏尼特左旗| 桦甸市| 丰顺县| 桓台县| 延川县| 马山县| 江阴市| 渭源县| 秭归县| 海盐县| 台中市| 英山县| 揭东县| 垫江县| 巴塘县|