Electron使用electron-builder打包時(shí)下載electron失敗或慢的解決方案

在打包或者運(yùn)行的時(shí)候,又時(shí)候會(huì)一直卡在再downloading url=https://github.com/electron/electron/releases/download/v11.2.1/electron-v11.2.1-win32-ia32.zip size=74 MB parts=8

解決方案如下:

electron-builder 在打包時(shí)會(huì)檢測(cè)cache中是否有electron 包,如果沒有的話會(huì)從github上拉去,在國(guó)內(nèi)網(wǎng)絡(luò)環(huán)境中拉取的過程大概率會(huì)失敗,所以你可以自己去下載一個(gè)包放到cache目錄里

各個(gè)平臺(tái)的目錄地址

Linux: $XDG_CACHE_HOME or ~/.cache/electron/
MacOS: ~/Library/Caches/electron/
Windows: %LOCALAPPDATA%/electron/Cache or ~/AppData/Local/electron/Cache/

參考:https://github.com/electron/get#how-it-works

例如在macos平臺(tái)打包electron應(yīng)用,執(zhí)行 electron-builder --mac --x64

?  clipboard git:(master) ? npm run dist

> clipboard@1.0.0 dist /Users/xx/workspace/electron/clipboard
> electron-builder --mac --x64

  ? electron-builder  version=22.3.2 os=18.7.0
  ? loaded configuration  file=package.json ("build" field)
  ? writing effective config  file=dist/builder-effective-config.yaml
  ? packaging       platform=darwin arch=x64 electron=8.0.0 appOutDir=dist/mac
  ? downloading     url=https://github.com/electron/electron/releases/download/v8.0.0/electron-v8.0.0-darwin-x64.zip size=66 MB parts=8

可以單獨(dú)下載這個(gè)包 https://github.com/electron/electron/releases/download/v8.0.0/electron-v8.0.0-darwin-x64.zip, 放到~/Library/Caches/electron/ 目錄下

windows 和 Linux可以同上同理,只是文件路徑放的地方不同

然后可以打包完成!

注:如果是下載依賴慢,可以切換源來(lái)處理

1.下載
在用戶下.npmrc配置文件中添加/修改下載源

registry=http://registry.npm.taobao.org/
disturl=https://npm.taobao.org/mirrors/node
electron_mirror=https://npm.taobao.org/mirrors/electron/

2.打包
替換下載源:electron-package加上參數(shù)

--download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/

taobao源或者其他源也是同上,更改就行了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容