发布步骤
此处用到的发布应用程序的工具是Electron Forge
1.导入Electron Forge到项目工程目录
npm install @electron-forge/cli --save-dev
npx electron-forge import
或者执行
npx @electron-forge/cli import
2.创建一个发布版本
npm run make
如果package.json加入了快捷发布指令
也可以通过执行
npm run-script package
3.查看发布版本
发布版本软件包在当前目录的out文件夹中
发布错误解决
Making for the following targets: squirrel
× Making for target: squirrel - On platform: win32 - For arch: x64
An unhandled error has occurred inside Forge:
An error occured while making for target: squirrel
Failed with exit code: 1
Output:
test.nuspec
Authors is required.
Description is required.
Error: Failed with exit code: 1
Output:
test.nuspec
Authors is required.
Description is required.
at ChildProcess.<anonymous> (E:\test\node_modules\electron-winstaller\src\sp
awn-promise.ts:52:16)
at ChildProcess.emit (events.js:182:13)
at ChildProcess.EventEmitter.emit (domain.js:441:20)
at maybeClose (internal/child_process.js:962:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 make: `electron-forge make`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@1.0.0 make script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2021-04-28T0
8_37_10_481Z-debug.log
从错误提示可以看出Authors和Description是必须的,如果前面执行npm init的时候,使用的是-y默认创建package.json,Authors和Description选项都是空,因此需要手动填写
打包步骤
此处用到asar以及NSIS
asar 是一种将多个文件合并成一个文件的类 tar 风格的归档格式
NSIS是一个专业开源的制作windows安装程序的工具
1.安装asar
npm install asar -g
2.使用asar打包
进到需要打包html的目录下,执行指令后会在对应的目录下生成一个.asar文件
asar pack ./main.html app.asar
3.将生成的.asar文件放在\out\electron_test-win32-x64\resources
4.使用nsis打包整个发布包生成exe
nsis打包流程如下链接:
nsis打包流程