Skip to main content
Version: 9.x

pnpm publish

将包发布到注册表。

¥Publishes a package to the registry.

pnpm [-r] publish [<tarball|folder>] [--tag <tag>]
[--access <public|restricted>] [options]

workspace 内发布包时,工作区根目录中的 LICENSE 文件会与包一起打包(除非包有自己的许可证)。

¥When publishing a package inside a workspace, the LICENSE file from the root of the workspace is packed with the package (unless the package has a license of its own).

你可以在发布前使用 package.json 中的 publishConfig 字段覆盖某些字段。你还可以使用 publishConfig.directory 自定义发布的子目录(通常使用第三方构建工具)。

¥You may override some fields before publish, using the publishConfig field in package.json. You also can use the publishConfig.directory to customize the published subdirectory (usually using third party build tools).

递归运行此命令时 (pnpm -r publish),pnpm 会将所有尚未发布版本的软件包发布到注册表。

¥When running this command recursively (pnpm -r publish), pnpm will publish all the packages that have versions not yet published to the registry.

选项

¥Options

--recursive, -r

发布工作区中的所有包。

¥Publish all packages from the workspace.

--json

以 JSON 格式显示信息。

¥Show information in JSON format.

--tag <tag>

发布带有给定标签的包。默认情况下,pnpm publish 更新 latest 标签。

¥Publishes the package with the given tag. By default, pnpm publish updates the latest tag.

例如:

¥For example:

# inside the foo package directory
pnpm publish --tag next
# in a project where you want to use the next version of foo
pnpm add foo@next

--access <public|restricted>

告诉注册中心发布的包应该是公开的还是受限制的。

¥Tells the registry whether the published package should be public or restricted.

--no-git-checks

不要检查当前分支是否是你的发布分支、干净且与远程保持同步。

¥Don't check if current branch is your publish branch, clean, and up-to-date with remote.

--publish-branch <branch>

  • 默认:master and main

    ¥Default: master and main

  • 类型:字符串

    ¥Types: String

存储库的主要分支,用于发布最新更改。

¥The primary branch of the repository which is used for publishing the latest changes.

--force

即使软件包的当前版本已在注册表中找到,也要尝试发布软件包。

¥Try to publish packages even if their current version is already found in the registry.

--report-summary

将已发布的包列表保存到 pnpm-publish-summary.json。当使用其他一些工具来报告已发布包的列表时很有用。

¥Save the list of published packages to pnpm-publish-summary.json. Useful when some other tooling is used to report the list of published packages.

pnpm-publish-summary.json 文件的示例:

¥An example of a pnpm-publish-summary.json file:

{
"publishedPackages": [
{
"name": "foo",
"version": "1.0.0"
},
{
"name": "bar",
"version": "2.0.0"
}
]
}

--dry-run

除了实际发布到注册表之外,执行发布会执行的所有操作。

¥Does everything a publish would do except actually publishing to the registry.

--otp

当发布需要双重身份验证的包时,此选项可以指定一次性密码。

¥When publishing packages that require two-factor authentication, this option can specify a one-time password.

--filter <package_selector>

了解有关过滤的更多信息。

¥Read more about filtering.

配置

¥Configuration

你还可以在 .npmrc 文件中设置 git-checkspublish-branch 选项。

¥You can also set git-checks, publish-branch options in the .npmrc file.

例如:

¥For example:

.npmrc
git-checks=false
publish-branch=production

生命周期脚本

¥Life Cycle Scripts

  • prepublishOnly

  • prepublish

  • prepack

  • prepare

  • postpack

  • publish

  • postpublish