目录
选择命令行版本:
目录
描述
¥Description
npm 从以下来源获取其配置值,按优先级排序:
¥npm gets its configuration values from the following sources, sorted by priority:
命令行标志
¥Command Line Flags
将 --foo bar
放在命令行上会将 foo
配置参数设置为 "bar"
。--
参数告诉 cli 解析器停止读取标志。在不指定任何值的情况下使用 --flag
会将值设置为 true
。
¥Putting --foo bar
on the command line sets the foo
configuration parameter to "bar"
. A --
argument tells the cli parser to stop reading flags. Using --flag
without specifying any value will set the value to true
.
示例:--flag1 --flag2
会将两个配置参数设置为 true
,而 --flag1 --flag2 bar
会将 flag1
设置为 true
,将 flag2
设置为 bar
。最后,--flag1 --flag2 -- bar
将两个配置参数都设置为 true
,并将 bar
作为命令参数。
¥Example: --flag1 --flag2
will set both configuration parameters to true
, while --flag1 --flag2 bar
will set flag1
to true
, and flag2
to bar
. Finally, --flag1 --flag2 -- bar
will set both configuration parameters to true
, and the bar
is taken as a command argument.
环境变量
¥Environment Variables
任何以 npm_config_
开头的环境变量都将被解释为配置参数。例如,将 npm_config_foo=bar
放入你的环境中会将 foo
配置参数设置为 bar
。任何未赋值的环境配置都将被赋值为 true
。配置值不区分大小写,因此 NPM_CONFIG_FOO=bar
的工作方式相同。但是,请注意,在 scripts
内部,npm 将设置自己的环境变量,并且 Node 会更喜欢那些小写版本,而不是你可能设置的任何大写版本。详情见 此问题。
¥Any environment variables that start with npm_config_
will be interpreted as a configuration parameter. For example, putting npm_config_foo=bar
in your environment will set the foo
configuration parameter to bar
. Any environment configurations that are not given a value will be given the value of true
. Config values are case-insensitive, so NPM_CONFIG_FOO=bar
will work the same. However, please note that inside scripts
npm will set its own environment variables and Node will prefer those lowercase versions over any uppercase ones that you might set. For details see this issue.
请注意,你需要使用下划线而不是破折号,因此 --allow-same-version
将变为 npm_config_allow_same_version=true
。
¥Notice that you need to use underscores instead of dashes, so --allow-same-version
would become npm_config_allow_same_version=true
.
npmrc 文件
¥npmrc Files
四个相关文件是:
¥The four relevant files are:
-
每个项目的配置文件 (
/path/to/my/project/.npmrc
)¥per-project configuration file (
/path/to/my/project/.npmrc
) -
每用户配置文件(默认为
$HOME/.npmrc
;可通过 CLI 选项--userconfig
或环境变量$NPM_CONFIG_USERCONFIG
配置)¥per-user configuration file (defaults to
$HOME/.npmrc
; configurable via CLI option--userconfig
or environment variable$NPM_CONFIG_USERCONFIG
) -
全局配置文件(默认为
$PREFIX/etc/npmrc
;可通过 CLI 选项--globalconfig
或环境变量$NPM_CONFIG_GLOBALCONFIG
配置)¥global configuration file (defaults to
$PREFIX/etc/npmrc
; configurable via CLI option--globalconfig
or environment variable$NPM_CONFIG_GLOBALCONFIG
) -
npm 的内置配置文件(
/path/to/npm/npmrc
)¥npm's built-in configuration file (
/path/to/npm/npmrc
)
有关详细信息,请参阅 npmrc。
¥See npmrc for more details.
默认配置
¥Default Configs
运行 npm config ls -l
以查看一组 npm 内部的配置参数,如果未指定其他参数,则为默认值。
¥Run npm config ls -l
to see a set of configuration parameters that are internal to npm, and are defaults if nothing else is specified.
速记和其他 CLI 细节
¥Shorthands and Other CLI Niceties
在命令行上解析以下简写:
¥The following shorthands are parsed on the command-line:
-
-a
:--all
-
--enjoy-by
:--before
-
-c
:--call
-
--desc
:--description
-
-f
:--force
-
-g
:--global
-
--iwr
:--include-workspace-root
-
-L
:--location
-
-d
:--loglevel info
-
-s
:--loglevel silent
-
--silent
:--loglevel silent
-
--ddd
:--loglevel silly
-
--dd
:--loglevel verbose
-
--verbose
:--loglevel verbose
-
-q
:--loglevel warn
-
--quiet
:--loglevel warn
-
-l
:--long
-
-m
:--message
-
--local
:--no-global
-
-n
:--no-yes
-
--no
:--no-yes
-
-p
:--parseable
-
--porcelain
:--parseable
-
-C
:--prefix
-
--readonly
:--read-only
-
--reg
:--registry
-
-S
:--save
-
-B
:--save-bundle
-
-D
:--save-dev
-
-E
:--save-exact
-
-O
:--save-optional
-
-P
:--save-prod
-
-?
:--usage
-
-h
:--usage
-
-H
:--usage
-
--help
:--usage
-
-v
:--version
-
-w
:--workspace
-
--ws
:--workspaces
-
-y
:--yes
如果指定的配置参数明确地解析为已知的配置参数,则将其扩展为该配置参数。例如:
¥If the specified configuration param resolves unambiguously to a known configuration parameter, then it is expanded to that configuration parameter. For example:
npm ls --par# same as:npm ls --parseable
如果多个单字符速记串在一起,并且生成的组合明确地不是某个其他配置参数,那么它会扩展为它的各个组成部分。例如:
¥If multiple single-character shorthands are strung together, and the resulting combination is unambiguously not some other configuration param, then it is expanded to its various component pieces. For example:
npm ls -gpld# same as:npm ls --global --parseable --long --loglevel info
配置设置
¥Config Settings
_auth
-
默认值:null
¥Default: null
-
类型:空值或字符串
¥Type: null or String
对 npm 注册表进行身份验证时使用的基本身份验证字符串。这将仅用于对 npm 注册表进行身份验证。对于其他注册表,你需要像 "//other-registry.tld/:_auth" 一样对其进行范围
¥A basic-auth string to use when authenticating against the npm registry. This will ONLY be used to authenticate against the npm registry. For other registries you will need to scope it like "//other-registry.tld/:_auth"
警告:这通常不应通过命令行选项设置。通过运行 npm login
使用存储在 ~/.npmrc 文件中的注册表提供的身份验证承载令牌更安全。
¥Warning: This should generally not be set via a command-line option. It is safer to use a registry-provided authentication bearer token stored in the ~/.npmrc file by running npm login
.
access
-
默认值:'restricted' 用于范围包,'public' 用于非范围包
¥Default: 'restricted' for scoped packages, 'public' for unscoped packages
-
类型:空值、"restricted" 或 "public"
¥Type: null, "restricted", or "public"
发布范围包时,访问级别默认为 restricted
。如果你希望你的范围包可公开查看(和可安装),请设置 --access=public
。access
的唯一有效值是 public
和 restricted
。无范围的包始终具有 public
的访问级别。
¥When publishing scoped packages, the access level defaults to restricted
. If you want your scoped package to be publicly viewable (and installable) set --access=public
. The only valid values for access
are public
and restricted
. Unscoped packages always have an access level of public
.
注意:在 npm publish
命令上使用 --access
标志只会在包的初始发布时设置包访问级别。任何使用 --access
标志的后续 npm publish
命令都不会影响访问级别。要在初始发布后更改访问级别,请使用 npm access
。
¥Note: Using the --access
flag on the npm publish
command will only set the package access level on the initial publish of the package. Any subsequent npm publish
commands using the --access
flag will not have an effect to the access level. To make changes to the access level after the initial publish use npm access
.
all
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
运行 npm outdated
和 npm ls
时,设置 --all
将显示所有过时或已安装的包,而不仅仅是当前项目直接依赖的包。
¥When running npm outdated
and npm ls
, setting --all
will show all outdated or installed packages, rather than only those directly depended upon by the current project.
allow-same-version
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
防止在使用 npm version
将新版本设置为与当前版本相同的值时引发错误。
¥Prevents throwing an error when npm version
is used to set the new version to the same value as the current version.
audit
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当 "true" 将审计报告与当前 npm 命令一起提交到默认注册表和为范围配置的所有注册表时。有关提交内容的详细信息,请参阅 npm audit
的文档。
¥When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes. See the documentation for npm audit
for details on what is submitted.
audit-level
-
默认值:null
¥Default: null
-
类型:空、"info"、"low"、"moderate"、"high"、"critical" 或 "none"
¥Type: null, "info", "low", "moderate", "high", "critical", or "none"
npm audit
以非零退出代码退出的最低漏洞级别。
¥The minimum level of vulnerability for npm audit
to exit with a non-zero exit code.
auth-type
-
默认值:"legacy"
¥Default: "legacy"
-
类型:"legacy"、"web"、"sso"、"saml"、"oauth" 或 "webauthn"
¥Type: "legacy", "web", "sso", "saml", "oauth", or "webauthn"
注意:auth-type 值 "sso"、"saml"、"oauth" 和 "webauthn" 将在未来版本中删除。
¥NOTE: auth-type values "sso", "saml", "oauth", and "webauthn" will be removed in a future version.
login
使用什么身份验证策略。
¥What authentication strategy to use with login
.
before
-
默认值:null
¥Default: null
-
类型:空或日期
¥Type: null or Date
如果传递给 npm install
,将重建 npm 树,以便仅安装 --before
时间或之前可用的版本。如果当前的直接依赖集没有可用的版本,则该命令将出错。
¥If passed to npm install
, will rebuild the npm tree such that only versions that were available on or before the --before
time get installed. If there's no versions available for the current set of direct dependencies, the command will error.
如果请求的版本是 dist-tag
并且给定的标签没有通过 --before
过滤器,则将使用小于或等于该标签的最新版本。例如,foo@latest
可能会安装 foo@1.2
,即使 latest
是 2.0
。
¥If the requested version is a dist-tag
and the given tag does not pass the --before
filter, the most recent version less than or equal to that tag will be used. For example, foo@latest
might install foo@1.2
even though latest
is 2.0
.
bin-links
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
告诉 npm 为包的可执行文件创建符号链接(或 Windows 上的 .cmd
垫片)。
¥Tells npm to create symlinks (or .cmd
shims on Windows) for package executables.
设置为 false 使其不执行此操作。这可以用来解决某些文件系统不支持符号链接的事实,即使在表面上是 Unix 系统上也是如此。
¥Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems.
browser
-
默认值:OS X:
"open"
,Windows:"start"
、其他:"xdg-open"
¥Default: OS X:
"open"
, Windows:"start"
, Others:"xdg-open"
-
类型:空值、布尔值或字符串
¥Type: null, Boolean, or String
npm 命令调用以打开网站的浏览器。
¥The browser that is called by npm commands to open websites.
设置为 false
以抑制浏览器行为,而是将 url 打印到终端。
¥Set to false
to suppress browser behavior and instead print urls to terminal.
设置为 true
以使用默认系统 URL 打开器。
¥Set to true
to use default system URL opener.
ca
-
默认值:null
¥Default: null
-
类型:null 或 String(可设置多次)
¥Type: null or String (can be set multiple times)
受信任的证书颁发机构签名证书,可用于与注册表的 SSL 连接。值应采用 PEM 格式(Windows 将其称为 "Base-64 编码的 X.509 (.CER)"),并用字符串 "\n" 替换换行符。例如:
¥The Certificate Authority signing certificate that is trusted for SSL connections to the registry. Values should be in PEM format (Windows calls it "Base-64 encoded X.509 (.CER)") with newlines replaced by the string "\n". For example:
ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
设置为 null
仅允许 "known" 注册商,或设置为特定 CA 证书以仅信任该特定签名机构。
¥Set to null
to only allow "known" registrars, or to a specific CA cert to trust only that specific signing authority.
通过指定证书数组可以信任多个 CA:
¥Multiple CAs can be trusted by specifying an array of certificates:
ca[]="..."ca[]="..."
另请参阅 strict-ssl
配置。
¥See also the strict-ssl
config.
cache
-
默认值:Windows:
%LocalAppData%\npm-cache
,Posix:~/.npm
¥Default: Windows:
%LocalAppData%\npm-cache
, Posix:~/.npm
-
类型:路径
¥Type: Path
npm 的缓存目录的位置。见 npm cache
¥The location of npm's cache directory. See npm cache
cafile
-
默认值:null
¥Default: null
-
类型:路径
¥Type: Path
包含一个或多个证书颁发机构签名证书的文件的路径。类似于 ca
设置,但允许多个 CA,以及将 CA 信息存储在磁盘上的文件中。
¥A path to a file containing one or multiple Certificate Authority signing certificates. Similar to the ca
setting, but allows for multiple CA's, as well as for the CA information to be stored in a file on disk.
call
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
npm exec
、npx
的可选配套选项,允许指定自定义命令与已安装的包一起运行。
¥Optional companion option for npm exec
, npx
that allows for specifying a custom command to be run along with the installed packages.
npm exec --package yo --package generator-node --call "yo node"
cert
-
默认值:null
¥Default: null
-
类型:空值或字符串
¥Type: null or String
访问注册表时要通过的客户端证书。值应采用 PEM 格式(Windows 将其称为 "Base-64 编码的 X.509 (.CER)"),并用字符串 "\n" 替换换行符。例如:
¥A client certificate to pass when accessing the registry. Values should be in PEM format (Windows calls it "Base-64 encoded X.509 (.CER)") with newlines replaced by the string "\n". For example:
cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
它不是证书文件的路径,但你可以设置注册表范围的 "certfile" 路径,如 "//other-registry.tld/:certfile=/path/to/cert.pem"。
¥It is not the path to a certificate file, though you can set a registry-scoped "certfile" path like "//other-registry.tld/:certfile=/path/to/cert.pem".
ci-name
-
默认值:当前 CI 系统的名称,如果不在已知 CI 平台上,则为
null
。¥Default: The name of the current CI system, or
null
when not on a known CI platform. -
类型:空值或字符串
¥Type: null or String
持续集成系统的名称。如果未明确设置,npm 将使用 @npmcli/ci-detect
模块检测当前 CI 环境。
¥The name of a continuous integration system. If not set explicitly, npm will detect the current CI environment using the @npmcli/ci-detect
module.
cidr
-
默认值:null
¥Default: null
-
类型:null 或 String(可设置多次)
¥Type: null or String (can be set multiple times)
这是使用 npm token create
命令配置受限访问令牌时要使用的 CIDR 地址列表。
¥This is a list of CIDR address to be used when configuring limited access tokens with the npm token create
command.
color
-
默认值:true 除非 NO_COLOR 环境设置为 '0' 以外的值
¥Default: true unless the NO_COLOR environ is set to something other than '0'
-
类型:"always" 或布尔值
¥Type: "always" or Boolean
如果为 false,则从不显示颜色。如果 "always"
则始终显示颜色。如果为真,则仅打印 tty 文件描述符的颜色代码。
¥If false, never shows colors. If "always"
then always shows colors. If true, then only prints color codes for tty file descriptors.
commit-hooks
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
使用 npm version
命令时运行 git commit hooks。
¥Run git commit hooks when using the npm version
command.
depth
-
默认值:如果设置了
--all
,则为Infinity
,否则为1
¥Default:
Infinity
if--all
is set, otherwise1
-
类型:空值或数字
¥Type: null or Number
为 npm ls
递归包时的深度。
¥The depth to go when recursing packages for npm ls
.
如果未设置,npm ls
将仅显示根项目的直接依赖。如果设置了 --all
,那么 npm 将默认显示所有依赖。
¥If not set, npm ls
will show only the immediate dependencies of the root project. If --all
is set, then npm will show all dependencies by default.
description
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
显示 npm search
中的描述
¥Show the description in npm search
diff
-
默认值:
¥Default:
-
类型:字符串(可以设置多次)
¥Type: String (can be set multiple times)
定义要在 npm diff
中比较的参数。
¥Define arguments to compare in npm diff
.
diff-dst-prefix
-
默认值:"b/"
¥Default: "b/"
-
类型:字符串
¥Type: String
npm diff
输出中使用的目标前缀。
¥Destination prefix to be used in npm diff
output.
diff-ignore-all-space
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
比较 npm diff
中的行时忽略空格。
¥Ignore whitespace when comparing lines in npm diff
.
diff-name-only
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
使用 npm diff
时仅打印文件名。
¥Prints only filenames when using npm diff
.
diff-no-prefix
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
不要在 npm diff
输出中显示任何源或目标前缀。
¥Do not show any source or destination prefix in npm diff
output.
注意:这会导致 npm diff
忽略 --diff-src-prefix
和 --diff-dst-prefix
配置。
¥Note: this causes npm diff
to ignore the --diff-src-prefix
and --diff-dst-prefix
configs.
diff-src-prefix
-
默认值:"a/"
¥Default: "a/"
-
类型:字符串
¥Type: String
npm diff
输出中使用的源前缀。
¥Source prefix to be used in npm diff
output.
diff-text
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
将所有文件视为 npm diff
中的文本。
¥Treat all files as text in npm diff
.
diff-unified
-
默认值:3
¥Default: 3
-
类型:数字
¥Type: Number
要在 npm diff
中打印的上下文行数。
¥The number of lines of context to print in npm diff
.
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.
editor
-
默认值:EDITOR 或 VISUAL 环境变量,或 Windows 上的 'notepad.exe',或 Unix 系统上的 'vim'
¥Default: The EDITOR or VISUAL environment variables, or 'notepad.exe' on Windows, or 'vim' on Unix systems
-
类型:字符串
¥Type: String
为 npm edit
和 npm config edit
运行的命令。
¥The command to run for npm edit
and npm config edit
.
engine-strict
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果设置为 true,那么 npm 将顽固地拒绝安装(甚至考虑安装)任何声称与当前 Node.js 版本不兼容的包。
¥If set to true, then npm will stubbornly refuse to install (or even consider installing) any package that claims to not be compatible with the current Node.js version.
这可以通过设置 --force
标志来覆盖。
¥This can be overridden by setting the --force
flag.
fetch-retries
-
默认值:2
¥Default: 2
-
类型:数字
¥Type: Number
从注册表获取包时要使用的 retry
模块的 "retries" 配置。
¥The "retries" config for the retry
module to use when fetching packages from the registry.
在网络故障或 5xx HTTP 错误的情况下,npm 将重试对注册表的幂等读取请求。
¥npm will retry idempotent read requests to the registry in the case of network failures or 5xx HTTP errors.
fetch-retry-factor
-
默认值:10
¥Default: 10
-
类型:数字
¥Type: Number
获取包时要使用的 retry
模块的 "factor" 配置。
¥The "factor" config for the retry
module to use when fetching packages.
fetch-retry-maxtimeout
-
默认值:60000(1 分钟)
¥Default: 60000 (1 minute)
-
类型:数字
¥Type: Number
获取包时要使用的 retry
模块的 "maxTimeout" 配置。
¥The "maxTimeout" config for the retry
module to use when fetching packages.
fetch-retry-mintimeout
-
默认值:10000(10 秒)
¥Default: 10000 (10 seconds)
-
类型:数字
¥Type: Number
获取包时要使用的 retry
模块的 "minTimeout" 配置。
¥The "minTimeout" config for the retry
module to use when fetching packages.
fetch-timeout
-
默认值:300000(5 分钟)
¥Default: 300000 (5 minutes)
-
类型:数字
¥Type: Number
等待 HTTP 请求完成的最长时间。
¥The maximum amount of time to wait for HTTP requests to complete.
force
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
删除了针对不幸的副作用、常见错误、不必要的性能下降和恶意输入的各种保护。
¥Removes various protections against unfortunate side effects, common mistakes, unnecessary performance degradation, and malicious input.
-
允许在全局安装中破坏非 npm 文件。
¥Allow clobbering non-npm files in global installs.
-
允许
npm version
命令在不干净的 git 存储库上工作。¥Allow the
npm version
command to work on an unclean git repository. -
允许使用
npm cache clean
删除缓存文件夹。¥Allow deleting the cache folder with
npm cache clean
. -
允许安装具有
engines
声明需要不同版本的 npm 的包。¥Allow installing packages that have an
engines
declaration requiring a different version of npm. -
允许安装具有
engines
声明需要不同版本node
的包,即使启用了--engine-strict
。¥Allow installing packages that have an
engines
declaration requiring a different version ofnode
, even if--engine-strict
is enabled. -
允许
npm audit fix
安装超出你声明的依赖范围的模块(包括 SemVer 的主要更改)。¥Allow
npm audit fix
to install modules outside your stated dependency range (including SemVer-major changes). -
允许取消发布已发布包的所有版本。
¥Allow unpublishing all versions of a published package.
-
允许在根项目中安装冲突的 peerDependencies。
¥Allow conflicting peerDependencies to be installed in the root project.
-
在
npm init
时隐式设置--yes
。¥Implicitly set
--yes
duringnpm init
. -
允许破坏
npm pkg
中的现有值¥Allow clobbering existing values in
npm pkg
-
允许取消发布整个包(不仅仅是单个版本)。
¥Allow unpublishing of entire packages (not just a single version).
如果你对自己想要做什么没有明确的想法,强烈建议你不要使用此选项!
¥If you don't have a clear idea of what you want to do, it is strongly recommended that you do not use this option!
foreground-scripts
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
在前台进程中运行已安装包的所有构建脚本(即 preinstall
、install
和 postinstall
)脚本,与主 npm 进程共享标准输入、输出和错误。
¥Run all build scripts (ie, preinstall
, install
, and postinstall
) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.
请注意,这通常会使安装运行速度变慢,并且噪音更大,但对调试很有用。
¥Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
format-package-lock
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
将 package-lock.json
或 npm-shrinkwrap.json
格式化为人类可读的文件。
¥Format package-lock.json
or npm-shrinkwrap.json
as a human readable file.
fund
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
当 "true" 在每个 npm install
的末尾显示消息时,确认正在寻找资金的依赖的数量。详见 npm fund
。
¥When "true" displays the message at the end of each npm install
acknowledging the number of dependencies looking for funding. See npm fund
for details.
git
-
默认值:"git"
¥Default: "git"
-
类型:字符串
¥Type: String
用于 git 命令的命令。如果计算机上安装了 git,但不在 PATH
中,则将其设置为 git 二进制文件的完整路径。
¥The command to use for git commands. If git is installed on the computer, but is not in the PATH
, then set this to the full path to the git binary.
git-tag-version
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
使用 npm version
命令时标记提交。将此设置为 false 会导致根本不进行任何提交。
¥Tag the commit when using the npm version
command. Setting this to false results in no commit being made at all.
global
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
在 "global" 模式下运行,以便将包安装到 prefix
文件夹而不是当前工作目录。有关行为差异的更多信息,请参见 文件夹。
¥Operates in "global" mode, so that packages are installed into the prefix
folder instead of the current working directory. See folders for more on the differences in behavior.
-
包安装到
{prefix}/lib/node_modules
文件夹,而不是当前工作目录。¥packages are installed into the
{prefix}/lib/node_modules
folder, instead of the current working directory. -
bin 文件链接到
{prefix}/bin
¥bin files are linked to
{prefix}/bin
-
手册页链接到
{prefix}/share/man
¥man pages are linked to
{prefix}/share/man
global-style
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
使 npm 以与全局 node_modules
文件夹相同的布局将包安装到本地 node_modules
文件夹中。只有你的直接依赖将显示在 node_modules
中,并且它们所依赖的所有内容都将展平在它们的 node_modules
文件夹中。这显然会消除一些数据去重。如果与 legacy-bundling
一起使用,则首选 legacy-bundling
。
¥Causes npm to install the package into your local node_modules
folder with the same layout it uses with the global node_modules
folder. Only your direct dependencies will show in node_modules
and everything they depend on will be flattened in their node_modules
folders. This obviously will eliminate some deduping. If used with legacy-bundling
, legacy-bundling
will be preferred.
globalconfig
-
默认值:全局 --prefix 设置加上 'etc/npmrc'。例如,'/usr/local/etc/npmrc'
¥Default: The global --prefix setting plus 'etc/npmrc'. For example, '/usr/local/etc/npmrc'
-
类型:路径
¥Type: Path
为全局配置选项读取的配置文件。
¥The config file to read for global config options.
heading
-
默认值:"npm"
¥Default: "npm"
-
类型:字符串
¥Type: String
启动所有调试日志输出的字符串。
¥The string that starts all the debugging log output.
https-proxy
-
默认值:null
¥Default: null
-
类型:空或网址
¥Type: null or URL
用于传出 https 请求的代理。如果设置了 HTTPS_PROXY
或 https_proxy
或 HTTP_PROXY
或 http_proxy
环境变量,则底层 make-fetch-happen
库将遵循代理设置。
¥A proxy to use for outgoing https requests. If the HTTPS_PROXY
or https_proxy
or HTTP_PROXY
or http_proxy
environment variables are set, proxy settings will be honored by the underlying make-fetch-happen
library.
if-present
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,当为 package.json
的 scripts
部分中未定义的脚本调用 run-script
时,npm 将不会退出并返回错误代码。当需要在脚本存在时选择性地运行脚本并在脚本失败时运行失败时,可以使用此选项。这很有用,例如,在运行可能仅适用于其他通用 CI 设置中的某些构建的脚本时。
¥If true, npm will not exit with an error code when run-script
is invoked for a script that isn't defined in the scripts
section of package.json
. This option can be used when it's desirable to optionally run a script when it's present and fail if the script fails. This is useful, for example, when running scripts that may only apply for some builds in an otherwise generic CI setup.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
ignore-scripts
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,npm 不会运行 package.json 文件中指定的脚本。
¥If true, npm does not run scripts specified in package.json files.
请注意,如果设置了 ignore-scripts
,则明确旨在运行特定脚本的命令(例如 npm start
、npm stop
、npm restart
、npm test
和 npm run-script
)仍将运行其预期的脚本,但它们不会运行任何前置或后置脚本。
¥Note that commands explicitly intended to run a particular script, such as npm start
, npm stop
, npm restart
, npm test
, and npm run-script
will still run their intended script if ignore-scripts
is set, but they will not run any pre- or post-scripts.
include
-
默认值:
¥Default:
-
类型:"prod"、"dev"、"optional"、"peer"(可多次设置)
¥Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
允许定义要安装的依赖类型的选项。
¥Option that allows for defining which types of dependencies to install.
这是 --omit=<type>
的倒数。
¥This is the inverse of --omit=<type>
.
--include
中指定的依赖类型将不会被忽略,无论命令行中指定省略/包含的顺序如何。
¥Dependency types specified in --include
will not be omitted, regardless of the order in which omit/include are specified on the command-line.
include-staged
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
允许安装由 npm RFC PR #92 定义的 "staged" 已发布包。
¥Allow installing "staged" published packages, as defined by npm RFC PR #92.
这是实验性的,不是由 npm 公共注册表实现的。
¥This is experimental, and not implemented by the npm public registry.
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.
init-author-email
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
默认情况下,值 npm init
应用于包作者的电子邮件。
¥The value npm init
should use by default for the package author's email.
init-author-name
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
默认情况下,应该使用值 npm init
作为包作者的名称。
¥The value npm init
should use by default for the package author's name.
init-author-url
-
默认值:""
¥Default: ""
-
类型:"" 或网址
¥Type: "" or URL
默认情况下,包作者的主页应使用值 npm init
。
¥The value npm init
should use by default for the package author's homepage.
init-license
-
默认值:"ISC"
¥Default: "ISC"
-
类型:字符串
¥Type: String
默认情况下,值 npm init
应用于包许可证。
¥The value npm init
should use by default for the package license.
init-module
-
默认值:"~/.npm-init.js"
¥Default: "~/.npm-init.js"
-
类型:路径
¥Type: Path
将由 npm init
命令加载的模块。有关详细信息,请参阅 init-package-json 模块的文档或 npm init。
¥A module that will be loaded by the npm init
command. See the documentation for the init-package-json module for more information, or npm init.
init-version
-
默认值:"1.0.0"
¥Default: "1.0.0"
-
类型:SemVer 字符串
¥Type: SemVer string
如果 package.json 中尚未设置,npm init
应该默认使用的值作为包版本号。
¥The value that npm init
should use by default for the package version number, if not already set in package.json.
install-links
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
设置文件时:存在于项目根之外的协议依赖将作为常规依赖打包和安装,而不是创建符号链接。此选项对工作区没有影响。
¥When set file: protocol dependencies that exist outside of the project root will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
json
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
是否输出 JSON 数据,而不是正常输出。
¥Whether or not to output JSON data, rather than the normal output.
-
在
npm pkg set
中,它可以使用 JSON.parse() 解析集合值,然后再将它们保存到你的package.json
。¥In
npm pkg set
it enables parsing set values with JSON.parse() before saving them to yourpackage.json
.
并非所有 npm 命令都支持。
¥Not supported by all npm commands.
key
-
默认值:null
¥Default: null
-
类型:空值或字符串
¥Type: null or String
访问注册表时要传递的客户端密钥。值应采用 PEM 格式,并用字符串 "\n" 替换换行符。例如:
¥A client key to pass when accessing the registry. Values should be in PEM format with newlines replaced by the string "\n". For example:
key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"
它不是密钥文件的路径,尽管你可以设置注册表范围的 "keyfile" 路径,如 "//other-registry.tld/:keyfile=/path/to/key.pem"。
¥It is not the path to a key file, though you can set a registry-scoped "keyfile" path like "//other-registry.tld/:keyfile=/path/to/key.pem".
legacy-bundling
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
使 npm 安装包,以便 1.4 之前的 npm 版本(例如 node 0.8 中包含的版本)可以安装包。这消除了所有自动数据去重。如果与 global-style
一起使用,则首选此选项。
¥Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping. If used with global-style
this option will be preferred.
legacy-peer-deps
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
导致 npm 在构建包树时完全忽略 peerDependencies
,就像在 npm 版本 3 到 6 中一样。
¥Causes npm to completely ignore peerDependencies
when building a package tree, as in npm versions 3 through 6.
如果一个包由于过于严格的 peerDependencies
冲突而无法安装,它提供了一种解决问题的方法。
¥If a package cannot be installed because of overly strict peerDependencies
that collide, it provides a way to move forward resolving the situation.
这与 --omit=peer
不同,因为 --omit=peer
将避免在磁盘上解包 peerDependencies
,但仍会设计一棵树,以便 peerDependencies
可以在正确的位置解包。
¥This differs from --omit=peer
, in that --omit=peer
will avoid unpacking peerDependencies
on disk, but will still design a tree such that peerDependencies
could be unpacked in a correct place.
不推荐使用 legacy-peer-deps
,因为它不会强制执行元依赖可能依赖的 peerDependencies
合约。
¥Use of legacy-peer-deps
is not recommended, as it will not enforce the peerDependencies
contract that meta-dependencies may rely on.
link
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
与 npm ls
一起使用,将输出限制为仅链接的那些包。
¥Used with npm ls
, limiting output to only those packages that are linked.
local-address
-
默认值:null
¥Default: null
-
类型:IP 地址
¥Type: IP Address
连接到 npm 注册表时使用的本地接口的 IP 地址。在 0.12 之前的 Node 版本中必须是 IPv4。
¥The IP address of the local interface to use when making connections to the npm registry. Must be IPv4 in versions of Node prior to 0.12.
location
-
默认值:"user" 除非传递
--global
,否则也会将此值设置为 "global"¥Default: "user" unless
--global
is passed, which will also set this value to "global" -
类型:"global"、"user" 或 "project"
¥Type: "global", "user", or "project"
当传递给 npm config
时,这指的是要使用的配置文件。
¥When passed to npm config
this refers to which config file to use.
当设置为 "global" 模式时,包将安装到 prefix
文件夹而不是当前工作目录。有关行为差异的更多信息,请参见 文件夹。
¥When set to "global" mode, packages are installed into the prefix
folder instead of the current working directory. See folders for more on the differences in behavior.
-
包安装到
{prefix}/lib/node_modules
文件夹,而不是当前工作目录。¥packages are installed into the
{prefix}/lib/node_modules
folder, instead of the current working directory. -
bin 文件链接到
{prefix}/bin
¥bin files are linked to
{prefix}/bin
-
手册页链接到
{prefix}/share/man
¥man pages are linked to
{prefix}/share/man
lockfile-version
-
默认值:版本 2 如果没有锁文件或当前锁文件版本小于等于 2,否则保持当前锁文件版本
¥Default: Version 2 if no lockfile or current lockfile version less than or equal to 2, otherwise maintain current lockfile version
-
类型:空、1、2、3、"1"、"2" 或 "3"
¥Type: null, 1, 2, 3, "1", "2", or "3"
设置要在 package-lock.json 和 npm-shrinkwrap-json 文件中使用的 lockfile 格式版本。可能的选项是:
¥Set the lockfile format version to be used in package-lock.json and npm-shrinkwrap-json files. Possible options are:
1:npm 版本 5 和 6 使用的锁定文件版本。缺少一些在安装过程中使用的数据,导致安装速度较慢且可能不太确定。在与旧的 npm 版本互操作时防止锁定文件流失。
¥1: The lockfile version used by npm versions 5 and 6. Lacks some data that is used during the install, resulting in slower and possibly less deterministic installs. Prevents lockfile churn when interoperating with older npm versions.
2:npm 版本 7 使用的默认锁定文件版本。包括版本 1 锁定文件数据和版本 3 锁定文件数据,以获得最大的确定性和互操作性,但以磁盘上的更多字节为代价。
¥2: The default lockfile version used by npm version 7. Includes both the version 1 lockfile data and version 3 lockfile data, for maximum determinism and interoperability, at the expense of more bytes on disk.
3:仅 npm 版本 7 中引入的新锁定文件信息。磁盘上比 lockfile 版本 2 小,但不能与旧的 npm 版本互操作。如果所有用户都使用 npm 版本 7 或更高版本,则非常理想。
¥3: Only the new lockfile information introduced in npm version 7. Smaller on disk than lockfile version 2, but not interoperable with older npm versions. Ideal if all users are on npm version 7 and higher.
loglevel
-
默认值:"notice"
¥Default: "notice"
-
类型:"silent"、"错误"、"warn"、"notice"、"http"、"timing"、"info"、"verbose" 或 "silly"
¥Type: "silent", "error", "warn", "notice", "http", "timing", "info", "verbose", or "silly"
要报告的日志级别。所有日志都写入调试日志,如果命令执行失败,则打印该文件的路径。
¥What level of logs to report. All logs are written to a debug log, with the path to that file printed if the execution of a command fails.
显示比设置更高级别的任何日志。默认值为 "notice"。
¥Any logs of a higher level than the setting are shown. The default is "notice".
另请参阅 foreground-scripts
配置。
¥See also the foreground-scripts
config.
logs-dir
-
默认值:缓存中名为
_logs
的目录¥Default: A directory named
_logs
inside the cache -
类型:空或路径
¥Type: null or Path
npm 的日志目录的位置。有关详细信息,请参阅 npm logging
。
¥The location of npm's log directory. See npm logging
for more information.
logs-max
-
默认值:10
¥Default: 10
-
类型:数字
¥Type: Number
要存储的最大日志文件数。
¥The maximum number of log files to store.
如果设置为 0,则不会为当前运行写入日志文件。
¥If set to 0, no log files will be written for the current run.
long
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
在 ls
、search
和 help-search
中显示扩展信息。
¥Show extended information in ls
, search
, and help-search
.
maxsockets
-
默认值:15
¥Default: 15
-
类型:数字
¥Type: Number
每个源使用的最大连接数(协议/主机/端口组合)。
¥The maximum number of connections to use per origin (protocol/host/port combination).
message
-
默认值:"%s"
¥Default: "%s"
-
类型:字符串
¥Type: String
npm version
在创建版本提交时使用的提交消息。
¥Commit message which is used by npm version
when creating version commit.
消息中的任何 "%s" 都将替换为版本号。
¥Any "%s" in the message will be replaced with the version number.
node-options
-
默认值:null
¥Default: null
-
类型:空值或字符串
¥Type: null or String
通过 NODE_OPTIONS
环境变量传递给 Node.js 的选项。这不会影响 npm 本身的执行方式,但会影响生命周期脚本的调用方式。
¥Options to pass through to Node.js via the NODE_OPTIONS
environment variable. This does not impact how npm itself is executed but it does impact how lifecycle scripts are called.
node-version
-
默认值:Node.js
process.version
值¥Default: Node.js
process.version
value -
类型:SemVer 字符串
¥Type: SemVer string
检查包的 engines
设置时使用的 node 版本。
¥The node version to use when checking a package's engines
setting.
noproxy
-
默认值:NO_PROXY 环境变量的值
¥Default: The value of the NO_PROXY environment variable
-
类型:字符串(可以设置多次)
¥Type: String (can be set multiple times)
应该绕过任何代理的域扩展。
¥Domain extensions that should bypass any proxies.
还接受逗号分隔的字符串。
¥Also accepts a comma-delimited string.
npm-version
-
默认值:
npm --version
的输出¥Default: Output of
npm --version
-
类型:SemVer 字符串
¥Type: SemVer string
检查包的 engines
设置时使用的 npm 版本。
¥The npm version to use when checking a package's engines
setting.
offline
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
强制离线模式:安装期间不会完成任何网络请求。要允许 CLI 填充缺失的缓存数据,请参阅 --prefer-offline
。
¥Force offline mode: no network requests will be done during install. To allow the CLI to fill in missing cache data, see --prefer-offline
.
omit
-
默认值:'dev' 如果
NODE_ENV
环境变量设置为 'production',否则为空。¥Default: 'dev' if the
NODE_ENV
environment variable is set to 'production', otherwise empty. -
类型:"dev"、"optional"、"peer"(可多次设置)
¥Type: "dev", "optional", or "peer" (can be set multiple times)
要从磁盘上的安装树中省略的依赖类型。
¥Dependency types to omit from the installation tree on disk.
请注意,这些依赖仍会被解析并添加到 package-lock.json
或 npm-shrinkwrap.json
文件中。它们只是没有物理安装在磁盘上。
¥Note that these dependencies are still resolved and added to the package-lock.json
or npm-shrinkwrap.json
file. They are just not physically installed on disk.
如果一个包类型同时出现在 --include
和 --omit
列表中,那么它将被包括在内。
¥If a package type appears in both the --include
and --omit
lists, then it will be included.
如果生成的省略列表包含 'dev'
,则 NODE_ENV
环境变量将针对所有生命周期脚本设置为 'production'
。
¥If the resulting omit list includes 'dev'
, then the NODE_ENV
environment variable will be set to 'production'
for all lifecycle scripts.
omit-lockfile-registry-resolved
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
此选项会导致 npm 为注册表依赖创建没有 resolved
密钥的锁定文件。后续安装将需要使用配置的注册表解析 tarball 端点,这可能会导致安装时间更长。
¥This option causes npm to create lock files without a resolved
key for registry dependencies. Subsequent installs will need to resolve tarball endpoints with the configured registry, likely resulting in a longer install time.
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.
pack-destination
-
默认值:"."
¥Default: "."
-
类型:字符串
¥Type: String
npm pack
将保存 tarball 的目录。
¥Directory in which npm pack
will save tarballs.
package
-
默认值:
¥Default:
-
类型:字符串(可以设置多次)
¥Type: String (can be set multiple times)
为 npm exec
安装的一个或多个包
¥The package or packages to install for npm exec
package-lock
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
如果设置为 false,则安装时忽略 package-lock.json
文件。如果 save
为真,这也将阻止写入 package-lock.json
。
¥If set to false, then ignore package-lock.json
files when installing. This will also prevent writing package-lock.json
if save
is true.
此配置不影响 npm ci
。
¥This configuration does not affect npm ci
.
package-lock-only
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果设置为 true,当前操作将只使用 package-lock.json
,忽略 node_modules
。
¥If set to true, the current operation will only use the package-lock.json
, ignoring node_modules
.
对于 update
,这意味着只会更新 package-lock.json
,而不是检查 node_modules
并下载依赖。
¥For update
this means only the package-lock.json
will be updated, instead of checking node_modules
and downloading dependencies.
对于 list
,这意味着输出将基于 package-lock.json
描述的树,而不是 node_modules
的内容。
¥For list
this means the output will be based on the tree described by the package-lock.json
, rather than the contents of node_modules
.
parseable
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
从写入标准输出的命令输出可解析的结果。对于 npm search
,这将是制表符分隔的表格格式。
¥Output parseable results from commands that write to standard output. For npm search
, this will be tab-separated table format.
prefer-offline
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,将绕过缓存数据的过时检查,但将从服务器请求丢失的数据。要强制完全离线模式,请使用 --offline
。
¥If true, staleness checks for cached data will be bypassed, but missing data will be requested from the server. To force full offline mode, use --offline
.
prefer-online
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,将强制检查缓存数据的时效性,使 CLI 立即查找更新,即使是新的包数据也是如此。
¥If true, staleness checks for cached data will be forced, making the CLI look for updates immediately even for fresh package data.
prefix
-
默认值:在全局模式下,安装 node 可执行文件的文件夹。在本地模式下,最近的父文件夹包含 package.json 文件或 node_modules 文件夹。
¥Default: In global mode, the folder where the node executable is installed. In local mode, the nearest parent folder containing either a package.json file or a node_modules folder.
-
类型:路径
¥Type: Path
安装全局项目的位置。如果在命令行上设置,则强制非全局命令在指定文件夹中运行。
¥The location to install global items. If set on the command line, then it forces non-global commands to run in the specified folder.
preid
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
"预发布标识符" 用作 semver 的 "prerelease" 部分的前缀。就像 1.2.0-rc.8
中的 rc
。
¥The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver. Like the rc
in 1.2.0-rc.8
.
progress
-
默认值:
true
除非在已知的 CI 系统中运行¥Default:
true
unless running in a known CI system -
类型:布尔值
¥Type: Boolean
当设置为 true
时,如果 process.stderr
是 TTY,npm 将在时间密集型操作期间显示进度条。
¥When set to true
, npm will display a progress bar during time intensive operations, if process.stderr
is a TTY.
设置为 false
以抑制进度条。
¥Set to false
to suppress the progress bar.
proxy
-
默认值:null
¥Default: null
-
类型:null、false 或 URL
¥Type: null, false, or URL
用于传出 http 请求的代理。如果设置了 HTTP_PROXY
或 http_proxy
环境变量,则底层 request
库将遵循代理设置。
¥A proxy to use for outgoing http requests. If the HTTP_PROXY
or http_proxy
environment variables are set, proxy settings will be honored by the underlying request
library.
read-only
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
这用于在使用 npm token create
命令配置受限访问令牌时将令牌标记为无法发布。
¥This is used to mark a token as unable to publish when configuring limited access tokens with the npm token create
command.
rebuild-bundle
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
安装后重建打包的依赖。
¥Rebuild bundled dependencies after installation.
registry
-
默认值:"https://registry.npmjs.org/"
¥Default: "https://registry.npmjs.org/"
-
类型:URL
¥Type: URL
npm 注册表的基本 URL。
¥The base URL of the npm registry.
replace-registry-host
-
默认值:"npmjs"
¥Default: "npmjs"
-
类型:"npmjs"、"never"、"always" 或字符串
¥Type: "npmjs", "never", "always", or String
定义用配置的注册表替换锁定文件中的注册表主机的行为。
¥Defines behavior for replacing the registry host in a lockfile with the configured registry.
默认行为是将包 dist URL 从默认注册表 (https://registry.npmjs.org) 替换为已配置的注册表。如果设置为 "never",则使用注册表值。如果设置为 "always",则每次都将注册表主机替换为配置的主机。
¥The default behavior is to replace package dist URLs from the default registry (https://registry.npmjs.org) to the configured registry. If set to "never", then use the registry value. If set to "always", then replace the registry host with the configured host every time.
你还可以指定一个裸主机名(例如,"registry.npmjs.org")。
¥You may also specify a bare hostname (e.g., "registry.npmjs.org").
save
-
默认值:
true
除非在使用npm update
时默认为false
¥Default:
true
unless when usingnpm update
where it defaults tofalse
-
类型:布尔值
¥Type: Boolean
将已安装的包作为依赖保存到 package.json
文件中。
¥Save installed packages to a package.json
file as dependencies.
与 npm rm
命令一起使用时,从 package.json
中删除依赖。
¥When used with the npm rm
command, removes the dependency from package.json
.
如果设置为 false
,也会阻止写入 package-lock.json
。
¥Will also prevent writing to package-lock.json
if set to false
.
save-bundle
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果在安装时使用 --save
、--save-dev
或 --save-optional
保存一个包,那么也将它放在 bundleDependencies
列表中。
¥If a package would be saved at install time by the use of --save
, --save-dev
, or --save-optional
, then also put it in the bundleDependencies
list.
如果设置了 --save-peer
,则忽略,因为无法打包 peerDependencies。
¥Ignored if --save-peer
is set, since peerDependencies cannot be bundled.
save-dev
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
将已安装的包保存到 package.json 文件中,名称为 devDependencies
。
¥Save installed packages to a package.json file as devDependencies
.
save-exact
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
保存到 package.json 的依赖将使用精确的版本进行配置,而不是使用 npm 的默认 semver 范围运算符。
¥Dependencies saved to package.json will be configured with an exact version rather than using npm's default semver range operator.
save-optional
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
将已安装的包保存到 package.json 文件中,名称为 optionalDependencies
。
¥Save installed packages to a package.json file as optionalDependencies
.
save-peer
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
将已安装的包保存到 package.json 文件中为 peerDependencies
¥Save installed packages to a package.json file as peerDependencies
save-prefix
-
默认值:"^"
¥Default: "^"
-
类型:字符串
¥Type: String
配置通过 --save
或 --save-dev
安装到 package.json 文件的包版本如何获得前缀。
¥Configure how versions of packages installed to a package.json file via --save
or --save-dev
get prefixed.
例如,如果一个包的版本为 1.2.3
,默认情况下其版本设置为 ^1.2.3
,允许对该包进行小幅升级,但在 npm config set save-prefix='~'
之后,它将设置为 ~1.2.3
,仅允许补丁升级。
¥For example if a package has version 1.2.3
, by default its version is set to ^1.2.3
which allows minor upgrades for that package, but after npm config set save-prefix='~'
it would be set to ~1.2.3
which only allows patch upgrades.
save-prod
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
将已安装的包专门保存到 dependencies
中。如果 devDependencies
或 optionalDependencies
中已经存在一个包,但你希望将其移动为非可选的生产依赖,这将非常有用。
¥Save installed packages into dependencies
specifically. This is useful if a package already exists in devDependencies
or optionalDependencies
, but you want to move it to be a non-optional production dependency.
如果 --save
为真,并且 --save-dev
或 --save-optional
都不为真,则这是默认行为。
¥This is the default behavior if --save
is true, and neither --save-dev
or --save-optional
are true.
scope
-
默认值:当前项目的范围(如果有)或 ""
¥Default: the scope of the current project, if any, or ""
-
类型:字符串
¥Type: String
将操作与范围注册表的作用域相关联。
¥Associate an operation with a scope for a scoped registry.
在登录或退出私有注册表时很有用:
¥Useful when logging in to or out of a private registry:
# log in, linking the scope to the custom registrynpm login --scope=@mycorp --registry=https://registry.mycorp.com# log out, removing the link and the auth tokennpm logout --scope=@mycorp
这将导致 @mycorp
映射到注册表,以便将来安装根据模式 @mycorp/package
指定的包。
¥This will cause @mycorp
to be mapped to the registry for future installation of packages specified according to the pattern @mycorp/package
.
这也将导致 npm init
创建一个范围包。
¥This will also cause npm init
to create a scoped package.
# accept all defaults, and create a package named "@foo/whatever",# instead of just named "whatever"npm init --scope=@foo --yes
script-shell
-
默认值:'/bin/sh' 在 POSIX 系统上,'cmd.exe' 在 Windows 上
¥Default: '/bin/sh' on POSIX systems, 'cmd.exe' on Windows
-
类型:空值或字符串
¥Type: null or String
用于脚本的 shell 与 npm exec
、npm run
和 npm init <package-spec>
命令一起运行。
¥The shell to use for scripts run with the npm exec
, npm run
and npm init <package-spec>
commands.
searchexclude
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
限制搜索结果的空格分隔选项。
¥Space-separated options that limit the results from search.
searchlimit
-
默认值:20
¥Default: 20
-
类型:数字
¥Type: Number
限制搜索结果的项目数。完全不适用于旧版搜索。
¥Number of items to limit search results to. Will not apply at all to legacy searches.
searchopts
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
始终传递给搜索的空格分隔选项。
¥Space-separated options that are always passed to search.
searchstaleness
-
默认值:900
¥Default: 900
-
类型:数字
¥Type: Number
如果使用旧版搜索端点,则在触发另一个注册表请求之前缓存的年龄(以秒为单位)。
¥The age of the cache, in seconds, before another registry request is made if using legacy search endpoint.
shell
-
默认值:SHELL 环境变量,或 Posix 上的 "bash",或 Windows 上的 "cmd.exe"
¥Default: SHELL environment variable, or "bash" on Posix, or "cmd.exe" on Windows
-
类型:字符串
¥Type: String
为 npm explore
命令运行的 shell。
¥The shell to run for the npm explore
command.
sign-git-commit
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果设置为 true,则 npm version
命令将使用 -S
提交新的包版本以添加签名。
¥If set to true, then the npm version
command will commit the new package version using -S
to add a signature.
请注意,git 要求你在 git 配置中设置 GPG 密钥才能正常工作。
¥Note that git requires you to have set up GPG keys in your git configs for this to work properly.
sign-git-tag
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果设置为 true,则 npm version
命令将使用 -s
标记版本以添加签名。
¥If set to true, then the npm version
command will tag the version using -s
to add a signature.
请注意,git 要求你在 git 配置中设置 GPG 密钥才能正常工作。
¥Note that git requires you to have set up GPG keys in your git configs for this to work properly.
strict-peer-deps
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果设置为 true
,而 --legacy-peer-deps
没有设置,那么任何冲突的 peerDependencies
都将被视为安装失败,即使 npm 可以根据非对等依赖合理地猜测出适当的解决方案。
¥If set to true
, and --legacy-peer-deps
is not set, then any conflicting peerDependencies
will be treated as an install failure, even if npm could reasonably guess the appropriate resolution based on non-peer dependency relationships.
默认情况下,依赖图中的冲突 peerDependencies
将使用最近的非对等依赖规范来解决,即使这样做会导致某些包收到超出其包的 peerDependencies
对象中设置的范围的对等依赖。
¥By default, conflicting peerDependencies
deep in the dependency graph will be resolved using the nearest non-peer dependency specification, even if doing so will result in some packages receiving a peer dependency outside the range set in their package's peerDependencies
object.
当执行这样的和覆盖时,会打印一个警告,解释冲突和所涉及的包。如果设置了 --strict-peer-deps
,则此警告被视为失败。
¥When such and override is performed, a warning is printed, explaining the conflict and the packages involved. If --strict-peer-deps
is set, then this warning is treated as a failure.
strict-ssl
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
通过 https 向注册表触发请求时是否进行 SSL 密钥验证。
¥Whether or not to do SSL key validation when making requests to the registry via https.
另请参阅 ca
配置。
¥See also the ca
config.
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 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.
tag-version-prefix
-
默认值:"v"
¥Default: "v"
-
类型:字符串
¥Type: String
如果设置,则在使用 npm-version
执行版本增量时更改标记新版本时使用的前缀。要完全删除前缀,请将其设置为空字符串:""
。
¥If set, alters the prefix used when tagging a new version when performing a version increment using npm-version
. To remove the prefix altogether, set it to the empty string: ""
.
因为其他工具可能依赖于 npm 版本标签看起来像 v1.0.0
的约定,所以只有在绝对必要时才使用这个属性。特别是,在为公共包覆盖此设置时要小心。
¥Because other tools may rely on the convention that npm version tags look like v1.0.0
, only use this property if it is absolutely necessary. In particular, use care when overriding this setting for public packages.
timing
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,则将调试日志写入缓存中的 logs-dir
并将计时信息写入 _timing.json
,即使命令成功完成也是如此。_timing.json
是 JSON 对象的换行符分隔列表。
¥If true, writes a debug log to logs-dir
and timing information to _timing.json
in the cache, even if the command completes successfully. _timing.json
is a newline delimited list of JSON objects.
你可以使用此 json 命令行快速查看它:npm exec -- json -g < ~/.npm/_timing.json
。
¥You can quickly view it with this json command line: npm exec -- json -g < ~/.npm/_timing.json
.
umask
-
默认值:0
¥Default: 0
-
类型:0000..0777 (0..511) 范围内的八进制数字字符串
¥Type: Octal numeric string in range 0000..0777 (0..511)
设置文件和文件夹的文件创建模式时使用的 "umask" 值。
¥The "umask" value to use when setting the file creation mode on files and folders.
文件夹和可执行文件被赋予一个模式,该模式被 0o777
屏蔽该值。其他文件的模式是 0o666
屏蔽此值。
¥Folders and executables are given a mode which is 0o777
masked against this value. Other files are given a mode which is 0o666
masked against this value.
请注意,底层系统也会将其自己的 umask 值应用于创建的文件和文件夹,npm 不会绕过这一点,而是将 --umask
配置添加到其中。
¥Note that the underlying system will also apply its own umask value to files and folders that are created, and npm does not circumvent this, but rather adds the --umask
config to it.
因此,大多数 POSIX 系统上有效的默认 umask 值是 0o22,这意味着文件夹和可执行文件以 0o755 模式创建,而其他文件以 0o644 模式创建。
¥Thus, the effective default umask value on most POSIX systems is 0o22, meaning that folders and executables are created with a mode of 0o755 and other files are created with a mode of 0o644.
unicode
-
默认值:在 Windows 上为 false,在具有 unicode 区域设置的 mac/unix 系统上为 true,如
LC_ALL
、LC_CTYPE
或LANG
环境变量所定义。¥Default: false on windows, true on mac/unix systems with a unicode locale, as defined by the
LC_ALL
,LC_CTYPE
, orLANG
environment variables. -
类型:布尔值
¥Type: Boolean
当设置为 true 时,npm 在树输出中使用 unicode 字符。当为 false 时,它使用 ascii 字符而不是 unicode 字形。
¥When set to true, npm uses unicode characters in the tree output. When false, it uses ascii characters instead of unicode glyphs.
update-notifier
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
设置为 false 以在使用比最新版本更旧的 npm 时抑制更新通知。
¥Set to false to suppress the update notification when using an older version of npm than the latest.
usage
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
显示有关指定命令的简短用法输出。
¥Show short usage output about the command specified.
user-agent
-
默认值:"npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}"
¥Default: "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}"
-
类型:字符串
¥Type: String
设置用户代理请求标头。以下字段将替换为其实际对应项:
¥Sets the User-Agent request header. The following fields are replaced with their actual counterparts:
-
{npm-version}
- 使用的 npm 版本¥
{npm-version}
- The npm version in use -
{node-version}
- 使用的 Node.js 版本¥
{node-version}
- The Node.js version in use -
{platform}
-process.platform
的值¥
{platform}
- The value ofprocess.platform
-
{arch}
-process.arch
的值¥
{arch}
- The value ofprocess.arch
-
{workspaces}
- 如果设置了workspaces
或workspace
选项,则设置为true
。¥
{workspaces}
- Set totrue
if theworkspaces
orworkspace
options are set. -
{ci}
-ci-name
配置的值,如果已设置,前缀为ci/
,如果ci-name
为空,则为空字符串。¥
{ci}
- The value of theci-name
config, if set, prefixed withci/
, or an empty string ifci-name
is empty.
userconfig
-
默认值:"~/.npmrc"
¥Default: "~/.npmrc"
-
类型:路径
¥Type: Path
用户级配置设置的位置。
¥The location of user-level configuration settings.
这可能会被 npm_config_userconfig
环境变量或 --userconfig
命令行选项覆盖,但不能被 globalconfig
文件中的设置覆盖。
¥This may be overridden by the npm_config_userconfig
environment variable or the --userconfig
command line option, but may not be overridden by settings in the globalconfig
file.
version
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,则输出 npm 版本并成功退出。
¥If true, output the npm version and exit successfully.
仅在命令行上明确指定时才相关。
¥Only relevant when specified explicitly on the command line.
versions
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
如果为 true,则输出 npm 版本以及 node 的 process.versions
映射和当前工作目录 package.json
文件中的版本(如果存在),并成功退出。
¥If true, output the npm version as well as node's process.versions
map and the version in the current working directory's package.json
file if one exists, and exit successfully.
仅在命令行上明确指定时才相关。
¥Only relevant when specified explicitly on the command line.
viewer
-
默认值:Posix 上的 "man",Windows 上的 "browser"
¥Default: "man" on Posix, "browser" on Windows
-
类型:字符串
¥Type: String
用于查看帮助内容的程序。
¥The program to use to view help content.
设置为 "browser"
以在默认 Web 浏览器中查看 html 帮助内容。
¥Set to "browser"
to view html help content in the default web browser.
which
-
默认值:null
¥Default: null
-
类型:空值或数字
¥Type: null or Number
如果有多个资金来源,打开哪个 1-indexed 来源 URL。
¥If there are multiple funding sources, which 1-indexed source URL to open.
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.
workspaces-update
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
如果设置为 true,npm cli 将在可能更改安装到 node_modules
文件夹的工作区的操作之后运行更新。
¥If set to true, the npm cli will run an update after operations that may possibly change the workspaces installed to the node_modules
folder.
yes
-
默认值:null
¥Default: null
-
类型:空值或布尔值
¥Type: null or Boolean
对 npm 可能在命令行上打印的任何提示自动回答 "yes"。
¥Automatically answer "yes" to any prompts that npm might print on the command line.
also
-
默认值:null
¥Default: null
-
类型:空值、"dev" 或 "development"
¥Type: null, "dev", or "development"
-
DEPRECATED:请改用 --include=dev。
¥DEPRECATED: Please use --include=dev instead.
当设置为 dev
或 development
时,这是 --include=dev
的别名。
¥When set to dev
or development
, this is an alias for --include=dev
.
cache-max
-
默认值:无穷
¥Default: Infinity
-
类型:数字
¥Type: Number
-
DEPRECATED:此选项已被
--prefer-online
弃用¥DEPRECATED: This option has been deprecated in favor of
--prefer-online
--cache-max=0
是 --prefer-online
的别名
¥--cache-max=0
is an alias for --prefer-online
cache-min
-
默认值:0
¥Default: 0
-
类型:数字
¥Type: Number
-
DEPRECATED:此选项已被
--prefer-offline
弃用。¥DEPRECATED: This option has been deprecated in favor of
--prefer-offline
.
--cache-min=9999 (or bigger)
是 --prefer-offline
的别名。
¥--cache-min=9999 (or bigger)
is an alias for --prefer-offline
.
dev
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
-
DEPRECATED:请改用 --include=dev。
¥DEPRECATED: Please use --include=dev instead.
--include=dev
的别名。
¥Alias for --include=dev
.
init.author.email
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
-
DEPRECATED:请改用
--init-author-email
。¥DEPRECATED: Use
--init-author-email
instead.
--init-author-email
的别名
¥Alias for --init-author-email
init.author.name
-
默认值:""
¥Default: ""
-
类型:字符串
¥Type: String
-
DEPRECATED:请改用
--init-author-name
。¥DEPRECATED: Use
--init-author-name
instead.
--init-author-name
的别名
¥Alias for --init-author-name
init.author.url
-
默认值:""
¥Default: ""
-
类型:"" 或网址
¥Type: "" or URL
-
DEPRECATED:请改用
--init-author-url
。¥DEPRECATED: Use
--init-author-url
instead.
--init-author-url
的别名
¥Alias for --init-author-url
init.license
-
默认值:"ISC"
¥Default: "ISC"
-
类型:字符串
¥Type: String
-
DEPRECATED:请改用
--init-license
。¥DEPRECATED: Use
--init-license
instead.
--init-license
的别名
¥Alias for --init-license
init.module
-
默认值:"~/.npm-init.js"
¥Default: "~/.npm-init.js"
-
类型:路径
¥Type: Path
-
DEPRECATED:请改用
--init-module
。¥DEPRECATED: Use
--init-module
instead.
--init-module
的别名
¥Alias for --init-module
init.version
-
默认值:"1.0.0"
¥Default: "1.0.0"
-
类型:SemVer 字符串
¥Type: SemVer string
-
DEPRECATED:请改用
--init-version
。¥DEPRECATED: Use
--init-version
instead.
--init-version
的别名
¥Alias for --init-version
only
-
默认值:null
¥Default: null
-
类型:空值、"prod" 或 "production"
¥Type: null, "prod", or "production"
-
DEPRECATED:使用
--omit=dev
从安装中省略开发依赖。¥DEPRECATED: Use
--omit=dev
to omit dev dependencies from the install.
当设置为 prod
或 production
时,这是 --omit=dev
的别名。
¥When set to prod
or production
, this is an alias for --omit=dev
.
optional
-
默认值:null
¥Default: null
-
类型:空值或布尔值
¥Type: null or Boolean
-
DEPRECATED:使用
--omit=optional
排除可选依赖,或使用--include=optional
包含它们。¥DEPRECATED: Use
--omit=optional
to exclude optional dependencies, or--include=optional
to include them.
除非另有省略,否则默认值会安装可选的 deps。
¥Default value does install optional deps unless otherwise omitted.
--include=optional 或 --omit=optional 的别名
¥Alias for --include=optional or --omit=optional
production
-
默认值:null
¥Default: null
-
类型:空值或布尔值
¥Type: null or Boolean
-
DEPRECATED:请改用
--omit=dev
。¥DEPRECATED: Use
--omit=dev
instead.
--omit=dev
的别名
¥Alias for --omit=dev
shrinkwrap
-
默认值:true
¥Default: true
-
类型:布尔值
¥Type: Boolean
-
DEPRECATED:请改用 --package-lock 设置。
¥DEPRECATED: Use the --package-lock setting instead.
--package-lock 的别名
¥Alias for --package-lock
sso-poll-frequency
-
默认值:500
¥Default: 500
-
类型:数字
¥Type: Number
-
DEPRECATED:SSO/SAML/OAuth 的 --auth-type 方法将在 npm 的未来版本中删除,以支持基于 Web 的登录。
¥DEPRECATED: The --auth-type method of SSO/SAML/OAuth will be removed in a future version of npm in favor of web-based login.
与启用 SSO 的 auth-type
一起使用时,配置在用户完成身份验证时轮询注册表的频率。
¥When used with SSO-enabled auth-type
s, configures how regularly the registry should be polled while the user is completing authentication.
sso-type
-
默认值:"oauth"
¥Default: "oauth"
-
类型:空值、"oauth" 或 "saml"
¥Type: null, "oauth", or "saml"
-
DEPRECATED:SSO/SAML/OAuth 的 --auth-type 方法将在 npm 的未来版本中删除,以支持基于 Web 的登录。
¥DEPRECATED: The --auth-type method of SSO/SAML/OAuth will be removed in a future version of npm in favor of web-based login.
如果为 --auth-type=sso
,则为要使用的 SSO 类型的类型。
¥If --auth-type=sso
, the type of SSO type to use.
tmp
-
默认值:Node.js
os.tmpdir()
方法返回的值 https://nodejs.cn/api/os.html#os_os_tmpdir¥Default: The value returned by the Node.js
os.tmpdir()
method https://nodejs.cn/api/os.html#os_os_tmpdir -
类型:路径
¥Type: Path
-
DEPRECATED:不再使用此设置。npm 将临时文件存储在缓存中的一个特殊位置,它们由
cacache
管理。¥DEPRECATED: This setting is no longer used. npm stores temporary files in a special location in the cache, and they are managed by
cacache
.
从历史上看,临时文件的存储位置。不再相关。
¥Historically, the location where temporary files were stored. No longer relevant.
也可以看看
¥See also