npm-dist-tag

概要

npm dist-tag add <pkg>@<version> [<tag>]
npm dist-tag rm <pkg> <tag>
npm dist-tag ls [<pkg>]

aliases: dist-tags

描述

添加,删除和列举包中的标签:

  • add:

  • rm:清除npm包中不再使用的标签。

  • ls:显示包的所有的标签。

示例

包发布者:

# 包npm-demos-test,历史版本1.0.0,1.0.1,1.0.2。当前版本1.0.3
> npm publish 
+ [email protected]

# 给版本1.0.2添加了标签tag2
> npm dist-tag add [email protected] tag2

包安装者:

通过tags直接安装包:

# npm install <pkg>@<tag>,如下安装1.0.2版本
> npm install npm-demos-test@tag2

如果安装的是添加到package.json依赖中的包:

# npm install --tag <tag>,效果同上
> npm install --tag tag2

latest标签

每次新发布包,都会默认为新发布版本打上latest标签:

# 包npm-demos-test
> npm publish
+ [email protected]

其实npm-demos-test已经打上了latest标签。若不想使用latest标签,发布时可以使用--tag主动设置:

> npm publish --tag=beta

对于用户来说,没有指定tags或者version下,默认安装latest的包:

# 如下默认安装打上latest标签的包
> npm install npm-demos-test

next标签

包如果还不够稳定,但是又想给别人测试使用,可以给这种即将上线的包的版本打上next标签。

警告

  • tag需与version共享同一个命名空间
  • tag不能标记version为范围区间的版本。如下情况会报错:
# 报错,因为version指定为范围"<1.0.2"
> npm dist-tag add npm-demos-test@<1.0.2 tag2

results matching ""

    No results matching ""