pnpm pack

从软件包中创建一个 tarball。

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. Padding in a step such as part{1..10..02}.js also pads the results to the wider endpoint's width. 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.

配置项#

--recursive, -r#

打包工作空间(Workspace)中的所有包。

--out <path>#

自定义 tarball 的输出路径。可以使用 %s 和 %v来添加软件包名称和版本,例如, %s.tgz 或 some-dir/%s-%v.tgz。默认情况下,tarball 以名称 <package-name>-<version>.tgz 保存在当前工作目录中。

--pack-destination <dir>#

pnpm pack 保存 tarball 的目录。默认值为当前目录。

--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 platform variant's archive also has its tag, and every archive of a package that declares publishConfig.variants has its targets. A dry run writes no archive, so it prints neither integrity nor size.

--variant <target>#

Pack only the archive of the publishConfig.variants entry that lists this target, such as --variant linux-x64-musl. --variant any packs the archive of every other host. Can be repeated. Without it, pnpm pack writes every archive the package declares, each platform variant as <name>-<version>~<tag>.tgz.

--filter <package_selector>#

阅读更多有关过滤的内容。

--dry-run#

做正常运行的一切,除了打包 tarball。可用于验证 tarball 包的内容。

--skip-manifest-obfuscation#

在打包后的清单中保留原始的 packageManager 字段和发布生命周期脚本,而不是将其剔除。 The pnpm field is still omitted, except for pnpm.config.

Life cycle scripts#

  • prepack
  • prepare
  • postpack

提示

你还可以使用 beforePacking 钩子 在创建 tarball 之前以编程方式修改 package.json 的内容。这对于删除仅用于开发的字段或添加发布元数据非常有用,而无需修改本地的 package.json。