在打包或者運(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 包案铺,如果沒(méi)有的話會(huì)從github上拉去控汉,在國(guó)內(nèi)網(wǎng)絡(luò)環(huán)境中拉取的過(guò)程大概率會(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源或者其他源也是同上磁携,更改就行了