問題描述
如何在沒有互聯網的情況下離線運行電子包裝器? (How to run electron‑packager offline without internet?)
我有一個 Angular 項目。我想將他轉換為桌面應用程序。為此,我使用 Electron.js。
我可以運行
electron .
它工作正常。
但現在我想製作一個 exe。為此,我想使用電子打包器。
問題:我運行:
electron‑packager . ‑‑platform=win32
錯誤:getaddrinfo EAI_AGAIN github.com
我知道electron‑packager需要github,但是怎麼解決呢?!再次,我在沒有互聯網的情況下離線工作(使用 jfrog artifactory)。
是否有另一個電子包可以在沒有互聯網的情況下做同樣的事情?(製作一個exe)
參考解法
方法 1:
The problem is that electron‑packager go to github.com to download electron.js.
So as @Alexander Leithner said to use electronZipDir option. (and also malept in electron channel in Discord)
The solution is simple, when you executed:
npm install electron
A zip file of the binaries of electron are cached in your computer.
The command for electron‑packager looks like this:
npm install ‑D electron‑packager
npx electron‑packager . ‑‑ platform=win32 ‑‑electronZipDir=C:/Users/baruc/AppData/Local/electron/Cache/**some long string**
Thats all
Edit 25/7/2021 Theoretically, electron‑packager has an option called "download" which you can pass to him a "cacheRoot" or "mirrorOptions" to download the electron.zip file. By default you dont need to change the cacheRoot, but unfortunately both options of the download didnt work for me.
BTW, mirrorOptions got an object, not a string. So its not clear how to pass an object from the command line.
I saw that in the file artifact‑utils.js of the @electron/get library, and there in the function called "mirrorVar" it search a special environment variables or the mirrorOptions which i tell before. If this function wont find them it will take the default which is github.
Solution when you have an artifactory:
Create in your project an .npmrc file and write there: ELECTRON_MIRROR="http://my mirror site/electron/" Be aware that it end with back slash.
Go to package.json file, and there to scripts write: "pac": "electron‑packager ‑‑ . ‑‑platform=win32"
3.execute it: npm run pac
(by Baruch Levin、Baruch Levin)