pnpm pack
パッケージのtarballを作成します。
Packing a package spec#
pnpm pack also accepts package specs, like npm pack <spec>:
pnpm pack foo@1.0.0downloads the tarball the registry resolves for the spec and saves it to the current directory. The spec may be a name, a version, a dist-tag, or a version range. pnpm verifies a registry download against the integrity declared in the registry metadata.pnpm pack github:user/repoclones a git repository and saves the tarball of the package it holds. It accepts the git specspnpm addaccepts, such as#<branch>,#semver:<range>, and#path:<dir>for a package in a sub-directory. If the package has apreparescript, pnpm installs the package's dependencies and runs the script, as it does for a git dependency on install. The package does not need anallowBuildsentry for this.--ignore-scriptsskips the scripts. Packing a git repository needsgiton thePATH.pnpm pack https://example.com/foo.tgzdownloads a tarball URL and saves it under the name and version from the tarball's ownpackage.json. The URL does not need to end in.tgz.pnpm pack ./dirpacks the project in./dir, saving the tarball to the current directory.pnpm pack ./foo.tgzsaves a local tarball file to the destination under the name and version from itspackage.json.
--dry-run, --out, and --pack-destination apply to specs the same way they apply to a project. With more than one spec, --json prints an array.
Files included in the tarball#
Use the files field in package.json to select files and directories. Patterns
support extglobs such as lib/!(*.test.js) and @(dist|lib). A files field
replaces the root .npmignore or .gitignore; ignore files inside selected
subdirectories still apply. An explicitly named file or internal symlink is
included even when its parent directory is excluded.
Brace ranges expand to individual values. For example, part{1..3}.js
matches part1.js, part2.js, and part3.js, and part{a..c}.js matches
parta.js, partb.js, and partc.js. Ranges support descending values,
steps such as part{1..5..2}.js, and zero padding such as part{01..03}.js.
A zero step uses the default increment of 1. Only the endpoints set the
padding, so part{1..10..02}.js matches part1.js, part3.js, and so on.
These ranges also work in .npmignore and .gitignore.
Without files, pnpm reads .npmignore, falling back to .gitignore.
Negated ignore patterns can re-include default exclusions such as *.orig and
npm-debug.log. Root lockfiles and .npmrc stay excluded.
Private workspace dependencies#
A package that is not private cannot list a private workspace package in
dependencies, because the private package is never published. Packing
such a package fails with ERR_PNPM_PRIVATE_WORKSPACE_DEPENDENCY. List the
private package in devDependencies instead, bundle it by listing it in
bundleDependencies with it installed, or remove the dependency in a
beforePacking hook.
Options#
--recursive, -r#
Pack all packages from the workspace.
--out <path>#
Customizes the output path for the tarball. Use %s and %v to include the package name and version, e.g., %s.tgz or some-dir/%s-%v.tgz. By default, the tarball is saved in the current working directory with the name <package-name>-<version>.tgz.
--pack-destination <dir>#
Directory in which pnpm pack will save tarballs. 初期値は現在の作業ディレクトリです。
--pack-gzip-level <level>#
The gzip compression level of the tarball, from 0 to 9. Values outside that range are rejected.
--json#
ログを JSON 形式で出力します。 Each archive written has an integrity, its SHA-512 in SRI form, and a size in bytes. A dry run writes no archive, so it prints neither.
The manifest field holds the package.json that goes into the tarball, after publishConfig and the other publish-time changes are applied. Run pnpm pack --dry-run --json to preview it without writing a tarball. A dry run still runs prepack and prepare, unless --ignore-scripts is passed.
--filter <package_selector>#
--dry-run#
Does everything a normal run does, except actually packing the tarball. Useful for verifying the contents of the tarball.
--ignore-pnpmfile#
Don't load the project's .pnpmfile.cjs, so its hooks, including beforePacking, don't run.
--ignore-scripts#
Don't run the prepack, prepare, and postpack scripts.
--skip-manifest-obfuscation#
Keep the original packageManager field and publish lifecycle scripts in the packed manifest instead of stripping them. The pnpm field is still omitted, except for pnpm.config.
Life cycle scripts#
prepackpreparepostpack
ヒント
You can also use the beforePacking hook to programmatically modify the package.json contents before the tarball is created. This is useful for removing development-only fields or adding publication metadata without modifying your local package.json.