首页·终端命令

npm publish

包与运行时

用法

npm publish [--access public] [--tag <tag>]

把包上传到 registry;带 @scope 的名字默认是私有的,所以要加 --access public,而版本号一旦用过就不能再用,先用 --dry-run 看清会打包哪些文件。

常用选项

选项含义
--access publicrequired for a scoped package, which is private by default
--tag <tag>publish under a tag such as next, leaving latest alone
--dry-runshow the file list and version without uploading
--otp <code>pass a two-factor code
--provenanceattach a signed build statement from CI

示例

npm publish --dry-run

shows exactly which files would ship

npm publish --access public

publishes @scope/name so anyone can install it

npm publish --tag next

a prerelease that npm install does not pick up

问题永远是什么装到哪里:装进这个项目,还是装到整台机器上。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. npm publish 是做什么的?

把包上传到 registry;带 @scope 的名字默认是私有的,所以要加 --access public,而版本号一旦用过就不能再用,先用 --dry-run 看清会打包哪些文件。

Q. 怎么写?

npm publish [--access public] [--tag <tag>] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man npm。这条命令属于包与运行时。

相关命令

man 手册: man npm-publish