目录

分发标签(dist-tags)是可读的标签,你可以用它们来组织和标记你发布的包的不同版本。dist-tags 补充了 语义化版本。除了比语义版本号更易于阅读之外,标签还允许发布者更有效地分发他们的包。

🌐 Distribution tags (dist-tags) are human-readable labels that you can use to organize and label different versions of packages you publish. dist-tags supplement semantic versioning. In addition to being more human-readable than semantic version numbering, tags allow publishers to distribute their packages more effectively.

有关更多信息,请参阅 dist-tag CLI 文档

🌐 For more information, see the dist-tag CLI documentation.

注意: 由于 dist-tags 与语义版本共享命名空间,请避免使用与现有版本号冲突的 dist-tags。我们建议避免使用以数字或字母“v”开头的 dist-tags。

发布带有 dist-tag 的包

🌐 Publishing a package with a dist-tag

默认情况下,运行 npm publish 会将你的包标记为 latest 分发标签。要使用其他分发标签,请在发布时使用 --tag 标志。

🌐 By default, running npm publish will tag your package with the latest dist-tag. To use another dist-tag, use the --tag flag when publishing.

  1. 在命令行上,导航到包的根目录。

    cd /path/to/package
  2. 运行以下命令,将 <tag> 替换为你想使用的标签:

    npm publish --tag <tag>

示例

🌐 Example

要使用 “beta” 分发标签发布包,请在命令行中在包的根目录运行以下命令:

🌐 To publish a package with the "beta" dist-tag, on the command line, run the following command in the root directory of your package:

npm publish --tag beta

将 dist-tag 添加到包的特定版本

🌐 Adding a dist-tag to a specific version of your package

  1. 在命令行上,导航到包的根目录。

    cd /path/to/package
  2. 运行以下命令,将 <package_name> 替换为你的包名,<version> 替换为你的包版本号,<tag> 替换为分发标签:

    npm dist-tag add <package-name>@<version> [<tag>]

示例

🌐 Example

要将“stable”标签添加到“example-package”包的1.4.0版本,你可以运行以下命令:

🌐 To add the "stable" tag to the 1.4.0 version of the "example-package" package, you would run the following command:

npm dist-tag add example-package@1.4.0 stable

目录