目录
选择命令行版本:
目录
概要
¥Synopsis
npm cialiases: clean-install, ic, install-clean, isntall-clean
描述
¥Description
此命令与 npm install
类似,不同之处在于它旨在用于自动化环境,例如测试平台、持续集成和部署 - 或任何你希望确保对依赖进行全新安装的情况。
¥This command is similar to npm install
, except it's meant to be used in automated environments such as test platforms, continuous integration, and deployment -- or any situation where you want to make sure you're doing a clean install of your dependencies.
使用 npm install
和 npm ci
的主要区别是:
¥The main differences between using npm install
and npm ci
are:
-
该项目必须具有现有的
package-lock.json
或npm-shrinkwrap.json
。¥The project must have an existing
package-lock.json
ornpm-shrinkwrap.json
. -
如果包锁中的依赖与
package.json
中的依赖不匹配,npm ci
将退出并出错,而不是更新包锁。¥If dependencies in the package lock do not match those in
package.json
,npm ci
will exit with an error, instead of updating the package lock. -
npm ci
一次只能安装整个项目:不能使用此命令添加单个依赖。¥
npm ci
can only install entire projects at a time: individual dependencies cannot be added with this command. -
如果
node_modules
已经存在,它将在npm ci
开始安装之前自动删除。¥If a
node_modules
is already present, it will be automatically removed beforenpm ci
begins its install. -
它永远不会写入
package.json
或任何包锁:安装基本上被冻结了。¥It will never write to
package.json
or any of the package-locks: installs are essentially frozen.
注意:如果你通过运行带有可能影响依赖树形状的标志(例如 --legacy-peer-deps
或 --install-links
)的 npm install
创建 package-lock.json
文件,则必须为 npm ci
提供相同的标志,否则你可能会遇到错误。一个简单的方法是运行例如 npm config set legacy-peer-deps=true --location=project
并将 .npmrc
文件提交到你的 repo。
¥NOTE: If you create your package-lock.json
file by running npm install
with flags that can affect the shape of your dependency tree, such as --legacy-peer-deps
or --install-links
, you must provide the same flags to npm ci
or you are likely to encounter errors. An easy way to do this is to run, for example, npm config set legacy-peer-deps=true --location=project
and commit the .npmrc
file to your repo.
示例
¥Example
确保你有一个包锁和一个最新的安装:
¥Make sure you have a package-lock and an up-to-date install:
$ cd ./my/npm/project$ npm installadded 154 packages in 10s$ ls | grep package-lock
在该项目中运行 npm ci
¥Run npm ci
in that project
$ npm ciadded 154 packages in 5s
将 Travis CI 配置为使用 npm ci
而不是 npm install
构建:
¥Configure Travis CI to build using npm ci
instead of npm install
:
# .travis.ymlinstall:- npm ci# keep the npm cache around to speed up installscache:directories:- "$HOME/.npm"
配置
¥Configuration
install-strategy
-
默认值:"hoisted"
¥Default: "hoisted"
-
类型:"hoisted"、"nested"、"shallow" 或 "linked"
¥Type: "hoisted", "nested", "shallow", or "linked"
设置在 node_modules 中安装包的策略。提升(默认):在顶层安装非复制,并在目录结构中根据需要复制。nested:(以前的 --legacy-bundling)就地安装,无需提升。浅层(以前的 --global-style)只在顶层安装直接的 deps。linked:(实验)安装在 node_modules/.store 中,链接到位,未提升。
¥Sets the strategy for installing packages in node_modules. hoisted (default): Install non-duplicated in top-level, and duplicated as necessary within directory structure. nested: (formerly --legacy-bundling) install in place, no hoisting. shallow (formerly --global-style) only install direct deps at top-level. linked: (experimental) install in node_modules/.store, link in place, unhoisted.
legacy-bundling
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
-
DEPRECATED:此选项已被
--install-strategy=nested
弃用¥DEPRECATED: This option has been deprecated in favor of
--install-strategy=nested
不要在 node_modules
中提升包安装,而是以与它们所依赖的方式相同的方式安装包。这可能会导致非常深的目录结构和重复的软件包安装,因为没有数据去重。设置 --install-strategy=nested
。
¥Instead of hoisting package installs in node_modules
, install packages in the same manner that they are depended on. This may cause very deep directory structures and duplicate package installs as there is no de-duplicating. Sets --install-strategy=nested
.
global-style
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
-
DEPRECATED:此选项已被
--install-strategy=shallow
弃用¥DEPRECATED: This option has been deprecated in favor of
--install-strategy=shallow
仅在顶层 node_modules
中安装直接依赖,但提升更深层次的依赖。设置 --install-strategy=shallow
。
¥Only install direct dependencies in the top level node_modules
, but hoist on deeper dependencies. Sets --install-strategy=shallow
.
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.
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.
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 an 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.
foreground-scripts
-
默认值:
false
除非使用npm pack
或npm publish
时默认为true
¥Default:
false
unless when usingnpm pack
ornpm publish
where it defaults totrue
-
类型:布尔值
¥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.
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.
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.
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.
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.
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.
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.
install-links
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
设置文件时:协议依赖将作为常规依赖打包和安装,而不是创建符号链接。此选项对工作区没有影响。
¥When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
也可以看看
¥See Also