9.6 应用程序打包
为了方便程序分发,可以通过 pkg 将 Node.js 项目打包为平台相关可执行文件。
首先安装 pkg
npm install -g pkg
编辑 package.json 文件,增加如下配置
{
"pkg": {
"scripts": "",
"assets": "keys/pubkey.pem",
"targets": [
"node14-linux-x64",
"node14-macos-x64",
"node14-win-x64"
],
"outputPath": "dist"
}
}
在 package.json 所在目录运行
pkg .
会在 dist 目录下生成 linux/macos/win 平台下的可执行文件