npm-ci
选择命令行版本:
See Details
目录
概要
¥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.