如何在沒有互聯網的情況下離線運行電子包裝器? (How to run electron-packager offline without internet?)


問題描述

如何在沒有互聯網的情況下離線運行電子包裝器? (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:

  1. 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.

  2. Go to package.json file, and there to scripts write: "pac": "electron‑packager ‑‑ . ‑‑platform=win32"

3.execute it: npm run pac

(by Baruch LevinBaruch Levin)

參考文件

  1. How to run electron‑packager offline without internet? (CC BY‑SA 2.5/3.0/4.0)

#electron-packager #electron






相關問題

哪個數據庫更適合用於電子窗口構建 (Which database is better to use with electron windows build)

使用 Electron Rebuilt 的 Electron Packager 腳本錯誤 (Electron Packager Script Error using Electron Rebuilt)

我可以在電子 package.json 中使用環境變量來獲取 osx 公證憑證嗎? (Can I use environment variables in electron package.json for osx notarize credentials?)

npm run make 在電子鍛造中不起作用 (npm run make is not working in electron-forge)

如何增加 window.localStorage 中限制的 ELECTRON 文件大小的大小限制? (How to increase the size limit of ELECTRON file size which is limited in window.localStorage?)

我應該如何排除電子打包器中的所有 node_modules (How should i exclude all node_modules in electron-packager)

如何在沒有互聯網的情況下離線運行電子包裝器? (How to run electron-packager offline without internet?)







留言討論