A tool for run pkg to package Node.js service or tool.
Why create @hz-9/pkg-build
instead of directly use pkg
?
@hz-9/pkg-build
still utilizes pkg for packaging operations without optimizations. @hz-9/pkg-build
provides the following functionalities:
- Supports
buildName
andbuildVersion
parameters. Default, it will read them from the package.json file. - The output artifacts will be rename
${name}-${version}-${platform}-${arch}
format.
npm install --global @hz-9/pkg-build
Get help:
pkg-build --help
Minimal execution:
pkg-build
With config file:
pkg-build --config ./.hz-9.conf.json
Please see config file description to learn how to write .hz-9.conf.json
.
The execution path, default is process.cwd()
. This parameter will affects the reading of the package.json
file and the resolution of other relative paths.
The path to the configuration file. If omitted, the configuration file is not read.
The command-line parameters have higher priority than configuration file parameters.
The name part of the build output filename. If omitted, it will read name
parameter from package.json
. If package.json cannot be found or parsed correctly, it will default to 'unknown'.
The version part of the build output filename. If omitted, it will read version
parameter from package.json
. If package.json cannot be found or parsed correctly, it will default to '0.0.0'.
The targets
parameter when execution pkg
. This is detail.
If export multi platforms, use ,
to separate them.(eg: linux-64,win-x64
) If omitted, it is linux-x64
.
The entry file path when execution pkg
. If ommited, it is ./src/index.js
.
The output folder path when execution pkg
. If ommited, it is ./build
.
The --config, --input-path, and --output-path parameters can all accept relative or absolute paths. Relative paths will be resolved using the root parameter as the base path.
The configuration file support jsonc
format. All parameters are prefixed with pkg
.
eg: Read buildName
parameter, will read the value of pkg.buildName
from the configuration file.
This is a template for a configuration file:
{
"pkg": {
"inputPath": "dist/main.js",
"buildName": "service",
"version": "0.0.0",
"targets": [
"linux-x64"
]
}
}
Equivalent to --build-name
. Has lower priority than command-line arguments.
Equivalent to --build-version
. Has lower priority than command-line arguments.
Equivalent to --targets
. Has lower priority than command-line arguments.
Equivalent to --input-path
. If a relative path is provided,it will be resolved using the path where the config
folder is located as the base path.
Equivalent to --output-path
. If a relative path is provided,it will be resolved using the path where the config
folder is located as the base path.
Since scripts
are fixed information in the project, we do not plan to support scripts
parameters in command-line.
Since assets
are fixed information in the project, we do not plan to support assets
parameters in command-line.