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

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

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

說明: vue2項目,使用的vue-element-admin框架,用electron打包成.exe文件。

1、新建一個文件夾,然后右鍵打開終端或者cd到這個目錄。執(zhí)行下面的命令(最好確認一下github網站是否登陸了)。

//將electron官網中的quick-start拉取到本地
git clone https://github.com/electron/electron-quick-start

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

2.安裝好后,用vscode(其他類似工具)打開,新建終端,前后輸入下面的命令。

//下載項目需要的依賴
npm install
//安裝打包.exe所需要的依賴electron-packager、electron
npm i electron-packager --save-dev
npm i electron --save-dev 
//運行看看是否可以成功
npm run start

如果運行成功,會彈出一個頁面,如下圖:

3、刪除electron-quick-start文件中的index.html,把自己的項目dist文件放進去。

4、打開electron-quick-start文件里的main.js文件,下面是mian.js完整代碼。

重點是: 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(); // 打開調試工具
}
// 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文件,添加上有關packager的代碼。

(PS: 如果不需要自動匹配dist文件夾下的應用圖標使用該內容
“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進行打包!打包成功后如下圖

npm run packager

到此這篇關于用electron將vue項目打包成.exe文件的文章就介紹到這了,更多相關electron vue打包內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

桃源县| 六盘水市| 香河县| 嘉鱼县| 武川县| 新余市| 邵武市| 德化县| 柳河县| 香河县| 北川| 阿拉善右旗| 涿州市| 南丰县| 郎溪县| 阿尔山市| 宣化县| 伽师县| 金秀| 屯门区| 漠河县| 图片| 大英县| 华蓥市| 永安市| 互助| 舟曲县| 宜城市| 德兴市| 长子县| 北流市| 太仆寺旗| 澄城县| 金阳县| 北宁市| 游戏| 常德市| 东阳市| 南丹县| 高邮市| 大邑县|