pnpm pack

Crea un tarball da un pacchetto.

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.

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.

Opzioni#

--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. Il valore predefinito รจ la cartella di lavoro corrente.

--pack-gzip-level <level>#

The gzip compression level of the tarball, from 0 to 9. Values outside that range are rejected.

--json#

Registra l'output in formato 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>#

Read more about filtering.

--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#

  • prepack
  • prepare
  • postpack

tip

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.