选择命令行版本:
🌐 Synopsis
npm publish <package-spec>
🌐 Description
将包发布到注册表,以便可以按名称安装。
🌐 Publishes a package to the registry so that it can be installed by name.
默认情况下,npm 会发布到公共注册表。可以通过指定不同的默认注册表或在名称中使用 scope,结合作用域配置的注册表来覆盖此行为(参见 package.json)。
🌐 By default npm will publish to the public registry. This can be overridden by specifying a different default registry or using a scope in the name, combined with a scope-configured registry (see package.json).
package 的解释方式与其他命令(如 npm install)相同,可以是:
🌐 A package is interpreted the same way as other commands (like npm install and can be:
package.json 文件描述的程序的文件夹<name>@<version>(参见 registry)以及 (c)<name>@<tag>(参见 npm dist-tag),指向 (d)<name><git remote url>如果指定注册表中已存在包名称和版本组合,则发布将失败。
🌐 The publish will fail if the package name and version combination already exists in the specified registry.
一旦某个软件包以特定名称和版本发布,该名称和版本的组合将永远不能再次使用,即使它通过 npm unpublish 被移除。
🌐 Once a package is published with a given name and version, that specific name and version combination can never be used again, even if it is removed with npm unpublish.
截至 npm@5,在发布过程中,将向注册表提交 tarball 的 sha1sum 以及带有 sha512sum 的完整性字段。随后的安装将使用支持的最强算法来验证下载内容。
🌐 As of npm@5, both a sha1sum and an integrity field with a sha512sum of the tarball will be submitted to the registry during publication. Subsequent installs will use the strongest supported algorithm to verify downloads.
类似于 --dry-run,请参见 npm pack,它会找出要包含的文件并将它们打包成一个 tar 文件上传到注册表。
🌐 Similar to --dry-run see npm pack, which figures out the files to be included and packs them into a tarball to be uploaded to the registry.
🌐 Files included in package
要查看你的包中将包含的内容,请运行 npm pack --dry-run。默认情况下会包含所有文件,但以下文件除外:
🌐 To see what will be included in your package, run npm pack --dry-run. All files are included by default, with the following exceptions:
与包安装和分发相关的某些文件总是会被包含。例如,package.json、README.md、LICENSE 等。
如果 package.json 中有一个“files”列表,那么只会包含指定的文件。(如果指定了目录,则会递归遍历目录及其内容,但仍遵循相同的忽略规则。)
如果存在 .gitignore 或 .npmignore 文件,那么该文件及所有子目录中被忽略的文件将不会包含在包中。如果两个文件都存在,则 .gitignore 会被忽略,仅使用 .npmignore。
.npmignore 文件遵循与 .gitignore 文件相同的模式规则
如果文件匹配某些模式,则它将_永远_不会被包含,除非明确添加到 package.json 中的 "files" 列表中,或者通过在 .npmignore 或 .gitignore 文件中的 ! 规则取消忽略。
符号链接从不包含在 npm 包中。
有关已发布软件包中包含内容的完整详情,以及软件包是如何构建的,请参见 developers。
🌐 See developers for full details on what's included in the published package, as well as details on how the package is built.
🌐 Configuration
tag如果你让 npm 安装一个包并且没有告诉它一个特定的版本,那么它会安装指定的标签。
🌐 If you ask npm to install a package and don't tell it a specific version, then it will install the specified tag.
同样,如果没有给出明确的标签,npm tag 命令指定的 package@version 也会添加该标签。
🌐 Also the tag that is added to the package@version specified by the npm tag command, if no explicit tag is given.
当被 npm diff 命令使用时,这是用于获取默认将与本地文件进行比较的 tarball 的标签。
🌐 When used by the npm diff command, this is the tag used to fetch the tarball that will be compared with the local files by default.
access如果你不希望你的作用域包被公开查看(和安装),请设置 --access=restricted。
🌐 If you do not want your scoped package to be publicly viewable (and installable) set --access=restricted.
未加作用域的包不能设置为 restricted。
🌐 Unscoped packages can not be set to restricted.
注意:默认情况下,这不会更改现有包的当前访问级别。在发布时指定 restricted 或 public 的值将像 npm access set status 一样更改现有包的访问权限。
🌐 Note: This defaults to not changing the current access level for existing packages. Specifying a value of restricted or public during publish will change the access for an existing package the same way that npm access set status would.
dry-run表示你不希望 npm 做出任何更改,并且它只应该报告本来会做的事情。这个选项可以传递给任何修改本地安装的命令,例如 install、update、dedupe、uninstall,以及 pack 和 publish。
🌐 Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, install, update, dedupe, uninstall, as well as pack and publish.
注意:其他与网络相关的命令(例如 dist-tags、owner 等)不支持此项。
🌐 Note: This is NOT honored by other network related commands, eg dist-tags, owner, etc.
otp这是来自双因素认证器的一次性密码。在使用 npm access 发布或更改软件包权限时需要此密码。
🌐 This is a one-time password from a two-factor authenticator. It's needed when publishing or changing package permissions with npm access.
如果未设置,并且注册表响应失败并询问一次性密码,npm 将在命令行上提示输入一次密码。
🌐 If not set, and a registry response fails with a challenge for a one-time password, npm will prompt on the command line for one.
workspace启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
🌐 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
workspace 配置的有效值为以下之一:
🌐 Valid values for the workspace config are either:
对于 npm init 命令设置时,可以将其设置为一个尚不存在的工作区文件夹,以创建该文件夹并将其作为项目内全新的工作区进行设置。
🌐 When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
workspaces设置为 true 以在 所有 配置的工作区上下文中运行命令。
🌐 Set to true to run the command in the context of all configured workspaces.
将此显式设置为 false 会导致像 install 这样的命令完全忽略工作区。如果不显式设置:
🌐 Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:
node_modules 树操作的命令(安装、更新等)会将工作区链接到 node_modules 文件夹。- 执行其他操作的命令(测试、执行、发布等)会在根项目上运行,除非 在 workspace 配置中指定了一个或多个工作区。此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
include-workspace-root为命令启用工作区时包括工作区根。
🌐 Include the workspace root when workspaces are enabled for a command.
当为 false 时,通过 workspace 配置指定单个工作区,或通过 workspaces 标志指定所有工作区,将导致 npm 仅在指定的工作区上操作,而不会在根项目上操作。
🌐 When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project.
此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
provenance从受支持的云 CI/CD 系统发布时,包将公开链接到它的构建和发布位置。
🌐 When publishing from a supported cloud CI/CD system, the package will be publicly linked to where it was built and published from.
此配置不能与:provenance-file 一起使用
🌐 This config can not be used with: provenance-file
provenance-file发布时,将使用给定路径的出处包。
🌐 When publishing, the provenance bundle at the given path will be used.
此配置不能与:provenance 一起使用
🌐 This config can not be used with: provenance
🌐 See Also