1.electron-builder組件使用原因
electron-vue 組件無法創(chuàng)建vue-cli 3.0項目,改用electron-builder插件
https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/#installation
vue-cli-plugin-electron-builder 和 electron-builder 是一個東東
yarn add electron-builder --save-dev
備注: 一直安裝失敗式曲,考慮將 npm更新 vue全局更新等操作孵滞,最終正常
2.在package.json中做如下配置
"build": {
"appId": "com.xxx.app",
"mac": {
"target": ["dmg","zip"]
},
"win": {
"target": ["nsis","zip"]
}
},
"scripts": {
"dist": "electron-builder --win --x64"
},
2.啟動web項目和啟動
啟動PC項目
# 開發(fā)
yarn electron:serve
npm run electron:serve
# 打包
yarn electron:build
npm run electron:build
打包失敗
Error: 'build' in the application package.json (/Users/tzt/Documents/vue/oil-system/dist_electron/bundled/package.json) is not supported since 3.0 anymore. Please move 'build' into the development package.json (/Users/tzt/Documents/vue/oil-system/package.json)
打包成安裝包,而非可執(zhí)行文件
elelctron-packager打包只是打包成各個平臺下可執(zhí)行文件苇侵,并不是安裝包乎串,如果需要打包成安裝包之類的可以參考electron-builder
常見問題
寫代碼的時候如果考慮到全平臺的使用,雖然electron可以打造跨平臺的應用旺上,但是前提是你你在代碼中做了相對應的處理,比如使用node在操作linux下面命令以及文件讀取和windows下有所不同糖埋,linux下文件有l(wèi)ink格式宣吱,我當時寫讀取目錄樹的時候就用錯方法導致將所有l(wèi)ink當成文件夾,進入死循環(huán)瞳别,這只是一個例子征候,還要好多坑
elelctron-packager打包只是打包成各個平臺下可執(zhí)行文件杭攻,并不是安裝包,如果需要打包成安裝包之類的可以參考electron-builder
打包成功后執(zhí)行如果直接報錯疤坝,這里如果你的代碼沒有問題的話兆解,有很大的原因是你的啟動文件main.js或者其他文件的路徑出錯,仔細檢查路徑跑揉,修改后重新打包即可
大家可以在electron的中文網(wǎng)上面加electron的交流群來交流學習關(guān)于electron的問題
5.安裝失敗
install electron with Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/electron/electron-tmp-download-4860-1517066058438'
yarn run v1.16.0
$ electron-builder --win --x64
? electron-builder version=20.44.4
? loaded configuration file=package.json ("build" field)
? description is missed in the package.json appPackageFile=/Users/tzt/Documents/vue/oil-system/package.json
? author is missed in the package.json appPackageFile=/Users/tzt/Documents/vue/oil-system/package.json
? writing effective config file=dist/builder-effective-config.yaml
? no native production dependencies
? packaging platform=win32 arch=x64 electron=5.0.6 appOutDir=dist/win-unpacked
? downloading parts=8 size=61 MB url=https://github.com/electron/electron/releases/download/v5.0.6/electron-v5.0.6-win32-x64.zip
? open /Users/tzt/Library/Caches/electron/623225114.zip.part5: permission denied
github.com/develar/go-fs-util.CloseAndCheckError
/Volumes/data/go/pkg/mod/github.com/develar/go-fs-util@v0.0.0-20190620175131-69a2d4542206/fs.go:117
github.com/develar/app-builder/pkg/download.(*Part).download
/Volumes/data/Documents/app-builder/pkg/download/Part.go:56
github.com/develar/app-builder/pkg/download.(*Downloader).DownloadResolved.func1.1
/Volumes/data/Documents/app-builder/pkg/download/downloader.go:114
github.com/develar/app-builder/pkg/util.MapAsyncConcurrency.func2
/Volumes/data/Documents/app-builder/pkg/util/async.go:67
runtime.goexit
/usr/local/Cellar/go/1.12.6/libexec/src/runtime/asm_amd64.s:1337
Error: /Users/tzt/Documents/vue/oil-system/node_modules/app-builder-bin/mac/app-builder exited with code 1
npm install -g electron --unsafe-perm=true --allow-root