首頁·終端機命令

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