配置
选择命令行版本:
See Details
目录
描述
¥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--userconfigor 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--globalconfigor 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
-
默认值:'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.
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
-
默认值:"web"
¥Default: "web"
-
类型:"legacy" 或 "web"
¥Type: "legacy" or "web"
login 使用什么身份验证策略。请注意,如果给出 otp 配置,则此值将始终设置为 legacy。
¥What authentication strategy to use with login. Note that if an otp config is given, this value will always be set to legacy.
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