通過 electron 和 electron-packager 生成mac桌面圖示
最近公司研發了一套內部使用的辦公系統包括移動端+PC端,系統是基於javaWeb開發的,PC端要求製作一個可安裝檔案以方便員工使用(url路徑記著有些麻煩),
於是想到了electron。由於之前用過所以window的exe包很容易就生成了,到了mac時候出現了一些問題........所以記錄下過程.
簡單介紹下:
Electron是由Github開發,用HTML,CSS和JavaScript來構建跨平臺桌面應用程式的一個開源庫。 Electron通過將Chromium和Node.js合併到同一個執行時環境中,並將其打包為Mac,Windows和Linux系統下的應用來實現這一目的。 Electron於2013年作為構建Github上可程式設計的文字編輯器Atom的框架而被開發出來。這兩個專案在2014春季開源。 |
因為是基於node的,所以預先要安裝node環境,具體安裝就不說了........
1. 快速生成新專案
npm init 這時候在目錄下會生成.json檔案,我的檔案package.json
{ |
2.安裝electron
npm install --save-dev electron
3.建立main.js
const electron = require('electron') const path = require('path') // Keep a global reference of the window object, if you don't, the window will function createWindow () { // and load the index.html of the app. // Open the DevTools. // Emitted when the window is closed. // This method will be called when Electron has finished // Quit when all windows are closed. app.on('activate', function () { |
4.最後直接執行命令
npm run-script package
ok,當前路徑下會生成一個dist的資料夾.app應用已經生成