Linux command
npm-publish 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Publish the package in the current directory
npm publish
Publish with a distribution tag (e.g. beta, next)
npm publish --tag [beta]
Publish a scoped package publicly
npm publish --access public
Simulate a publish without uploading
npm publish --dry-run
Publish a specific tarball or folder
npm publish [./package.tgz]
Publish with 2FA one-time password
npm publish --otp=[123456]
Publish with supply-chain provenance (CI only)
npm publish --provenance --access public
说明
npm publish packs the current project (or a given folder/tarball) and uploads it to the configured registry, making the new version installable by others. Files included in the tarball follow the rules in `.npmignore`, the `files` field of `package.json`, and the standard npm defaults. The `name` and `version` fields must together be unique on the registry; republishing an already-published version is not allowed. For scoped packages (`@scope/name`), npm treats the package as private by default; pass `--access public` on first publish to make it publicly available.
参数
- --tag _TAG_
- Register the published version under the given dist-tag instead of `latest`.
- --access _restricted_|_public_
- Set initial access for a scoped package. Required as `public` for new scoped packages or when using `--provenance`.
- --dry-run
- Report what would be published without uploading anything.
- --otp _CODE_
- Supply a one-time password from a 2FA authenticator.
- --provenance
- Generate and attach a supply-chain provenance statement (npm >= 9.5.0, supported CI only).
- --provenance-file _FILE_
- Attach a pre-generated provenance bundle instead of creating one.
- -w, --workspace _NAME_
- Publish a specific workspace package.
- --workspaces
- Publish every configured workspace.
- --include-workspace-root
- Also include the workspace root when `--workspaces` is used.
- --help
- Display help information.
FAQ
What is the npm-publish command used for?
npm publish packs the current project (or a given folder/tarball) and uploads it to the configured registry, making the new version installable by others. Files included in the tarball follow the rules in `.npmignore`, the `files` field of `package.json`, and the standard npm defaults. The `name` and `version` fields must together be unique on the registry; republishing an already-published version is not allowed. For scoped packages (`@scope/name`), npm treats the package as private by default; pass `--access public` on first publish to make it publicly available.
How do I run a basic npm-publish example?
Run `npm publish` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --tag _TAG_ do in npm-publish?
Register the published version under the given dist-tag instead of `latest`.