electron-builder 的使用

electron-builder 的使用

前言

使用electron-vue开发一个electron跨平台项目。

安装 vue-cli 和 脚手架样板代码

npm install -g vue-cli
vue init simulatedgreg/electron-vue my-project

安装依赖并运行你的程序

cd my-project
yarn # 或者 npm install
yarn run dev # 或者 npm run dev

开发完成打包

使用 vue init simulatedgreg/electron-vue my-project 自带的package.json 中的script

“build”: “node .electron-vue/build.js && electron-builder”,
“build:dir”: “node .electron-vue/build.js && electron-builder --dir”,
“build:clean”: “cross-env BUILD_TARGET=clean node .electron-vue/build.js”,
“build:web”: “cross-env BUILD_TARGET=web node .electron-vue/build.js”,
用法:
yarn run build 等。

自定义使用script

“win32”: “electron-builder --win --ia32”,
“win64”: “electron-builder --win --x64”,
“mac”: “electron-builder --mac”,
“linux”: “electron-builder --linux”,
用法:
yarn run win32
yarn run win64
yarn run mac
yarn run linux
使用上述两种打包 Windows平台下的发现都会报错,并抛出异常
可以把这两个包 放在 devDependencies中
npm i electron-packager --save-dev
npm i electron-windows-installer --save-dev

然后在打包。
这个时候就是考验网络的时候。

error

Downloading tmp-6275-0-electron-v1.8.6-win32-ia32.zip
Error: read ECONNRESET
Error: read ECONNRESET

如果打包Windows下抛出这种异常,是网络不行。可以翻个墙并提一下网速(这个影响真的很大)

electron-builder的全部用法

Building:
–mac, -m, -o, --macos Build for macOS, accepts target list (see
https://goo.gl/5uHuzj). [数组]

–linux, -l Build for Linux, accepts target list (see
https://goo.gl/4vwQad) [数组]

–win, -w, --windows Build for Windows, accepts target list (see
https://goo.gl/jYsTEJ) [数组]

–x64 Build for x64 [布尔]

–ia32 Build for ia32 [布尔]

–armv7l Build for armv7l [布尔
]
–dir Build unpacked dir. Useful to test. [布尔]

–extraMetadata, --em Deprecated. Use -c.extraMetadata.

–prepackaged, --pd The path to prepackaged app (to pack in a
distributable format)

–projectDir, --project The path to project directory. Defaults to current
working directory.

–config, -c The path to an electron-builder config. Defaults to
electron-builder.yml (or json, or json5), see
https://goo.gl/YFRJOM

Publishing:
–publish, -p Publish artifacts (to GitHub Releases), see
https://goo.gl/tSFycD
[可选值: “onTag”, “onTagOrDraft”, “always”, “never”, undefined]

Deprecated:
–draft Please set releaseType in the GitHub publish options instead
[布尔]

–prerelease Please set releaseType in the GitHub publish options instead
[布尔]

–platform The target platform (preferred to use --mac, --win or --linux)
[可选值: “mac”, “win”, “linux”, “darwin”, “win32”, “all”, undefined]

–arch The target arch (preferred to use --x64 or --ia32)
[可选值: “ia32”, “x64”, “all”, undefined]

Other:
–help 显示帮助信息 [布尔]
–version 显示版本号 [布尔]

示例:
electron-builder -mwl build for macOS, Windows and Linux
electron-builder --linux deb tar.xz build deb and tar.xz for Linux
electron-builder --win --ia32 build for Windows ia32
electron-builder --em.foo=bar set package.json property foo to
bar
electron-builder configure unicode options for NSIS
–config.nsis.unicode=false

猜你喜欢

转载自blog.csdn.net/guoqiankunmiss/article/details/88787747