选择命令行版本:
See Details
目录
概要
¥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:
-
a) 包含由
package.json
文件描述的程序的文件夹¥a) a folder containing a program described by a
package.json
file -
b) 一个 gzipped tarball,包含 (a)
¥b) a gzipped tarball containing (a)
-
c) 解析为 (b) 的 url
¥c) a url that resolves to (b)
-
d) 在注册表上发布的
<name>@<version>
(参见registry
),带有 (c)¥d) a
<name>@<version>
that is published on the registry (seeregistry
) with (c) -
e) 指向 (d) 的
<name>@<tag>
(见npm dist-tag
)¥e) a
<name>@<tag>
(seenpm dist-tag
) that points to (d) -
f) 具有满足 (e) 的 "latest" 标签的
<name>
¥f) a
<name>
that has a "latest" tag satisfying (e) -
g) 解决为 (a) 的
<git remote url>
¥g) a
<git remote url>
that resolves to (a)
如果指定注册表中已存在包名称和版本组合,则发布将失败。
¥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
开始,在发布期间,将在发布期间将 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
,它计算出要包含的文件并将它们打包到一个 tarball 中以上传到注册表。
¥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
等。¥Certain files that are relevant to package installation and distribution are always included. For example,
package.json
,README.md
,LICENSE
, and so on. -
如果
package.json
中有 "files" 列表,则仅包含指定的文件。(如果指定了目录,那么它们将被递归遍历并包含它们的内容,遵循相同的忽略规则。)¥If there is a "files" list in
package.json
, then only the files specified will be included. (If directories are specified, then they will be walked recursively and their contents included, subject to the same ignore rules.) -
如果有
.gitignore
或.npmignore
文件,则其中被忽略的文件和所有子目录都将从包中排除。如果两个文件都存在,则忽略.gitignore
,只使用.npmignore
。¥If there is a
.gitignore
or.npmignore
file, then ignored files in that and all child directories will be excluded from the package. If both files exist, then the.gitignore
is ignored, and only the.npmignore
is used..npmignore
文件跟随 相同的模式规则 为.gitignore
文件¥
.npmignore
files follow the same pattern rules as.gitignore
files -
如果文件与某些模式匹配,则永远不会包含它,除非明确添加到
package.json
中的"files"
列表中,或者在.npmignore
或.gitignore
文件中使用!
规则取消忽略。¥If the file matches certain patterns, then it will never be included, unless explicitly added to the
"files"
list inpackage.json
, or un-ignored with a!
rule in a.npmignore
or.gitignore
file. -
符号链接从不包含在 npm 包中。
¥Symbolic links are never included in npm packages.
有关已发布包中包含的内容以及如何构建包的详细信息,请参阅 developers
。
¥See developers
for full details on what's included in the published package, as well as details on how the package is built.
有关可以和不能忽略的内容的更多信息,请参阅 package.json
。
¥See package.json
for more info on what can and can't be ignored.
配置
¥Configuration
tag
-
默认值:"latest"
¥Default: "latest"
-
类型:字符串
¥Type: String
如果你让 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 dist-tag add
命令中指定的 package@version 的标签。
¥It is the tag added to the package@version specified in the npm dist-tag add
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.
如果在 npm publish
命令中使用,这是将添加到提交到注册表的包的标签。
¥If used in the npm publish
command, this is the tag that will be added to the package submitted to the registry.
access
-
默认值:'public' 用于新包,现有包不会改变当前级别
¥Default: 'public' for new packages, existing packages it will not change the current level
-
类型:空值、"restricted" 或 "public"
¥Type: null, "restricted", or "public"
如果你不希望你的范围包公开可见(和可安装),请设置 --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
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
表示你不希望 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
-
默认值:null
¥Default: null
-
类型:空值或字符串
¥Type: null or String
这是来自双重身份验证器的一次性密码。使用 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
-
默认值:
¥Default:
-
类型:字符串(可以设置多次)
¥Type: String (can be set multiple times)
启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
¥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:
-
工作区名称
¥Workspace names
-
工作区目录的路径
¥Path to a workspace directory
-
父工作区目录的路径(将导致选择该文件夹中的所有工作区)
¥Path to a parent workspace directory (will result in selecting all workspaces within that folder)
为 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
-
默认值:null
¥Default: null
-
类型:空值或布尔值
¥Type: null or Boolean
设置为 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
配置中指定了一个或多个工作区。¥Commands that operate on the
node_modules
tree (install, update, etc.) will link workspaces into thenode_modules
folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, unless one or more workspaces are specified in theworkspace
config.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
include-workspace-root
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
为命令启用工作区时包括工作区根。
¥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
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
从受支持的云 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
-
默认值:null
¥Default: null
-
类型:路径
¥Type: Path
发布时,将使用给定路径的出处包。
¥When publishing, the provenance bundle at the given path will be used.
此配置不能用于:provenance
¥This config can not be used with: provenance
也可以看看
¥See Also