从npm文档中:
简而言之,使用npm安装和npm配置项之间的主要区别是:
本质上,npm install
读取package.json
以创建依赖项列表,并使用package-lock.json
通知要安装哪些版本的依赖项。如果依赖项不在package-lock.json
中,它将由npm install
添加。
npm ci
(以持续集成命名)直接从package-lock.json
安装依赖项,并仅使用package.json
验证不存在不匹配的版本。如果缺少任何依赖项或有不兼容的版本,它将抛出错误。
使用npm install
添加新的依赖项,并更新项目的依赖项。通常,您将在开发过程中在提取更新依赖项列表的更改之后使用它,但是在这种情况下使用npmci
可能是一个好主意。
如果需要确定的,可重复的构建,请使用NPM CI
。例如在持续集成,自动化作业等过程中,以及第一次安装依赖项时,而不是npm install
。
npm-shrinkwrap.json
和package-lock.json
(按此顺序)驱动。node_modules
中缺少的任何依赖项。package.json
或package-lock.json
。
npm i packageName
)一起使用时,它可能会写入package.json
以添加或更新依赖项。npm i
)它可能会写入package-lock.json
以锁定某些依赖项的版本,如果这些依赖项不在此文件中。package-lock.json
或npm-shrinkwrap.json
。package.json
不匹配,node_modules
并一次安装所有依赖项。package.json
或package-lock.json
。当npm ci
从package-lock.json
或npm-shrinkwrap.json
生成整个依赖关系树时,npm install
使用以下算法(源)更新node_modules
的内容:
load the existing node_modules tree from disk
clone the tree
fetch the package.json and assorted metadata and add it to the clone
walk the clone and add any missing dependencies
dependencies will be added as close to the top as is possible
without breaking any other modules
compare the original tree with the cloned tree and make a list of
actions to take to convert one to the other
execute all of the actions, deepest first
kinds of actions are install, update, remove and move
npmci
将删除任何现有的node_modules文件夹,并依赖于package-lock.json
文件来安装每个包的特定版本。它比npm安装要快得多,因为它跳过了一些功能。它的清洁状态安装是伟大的CI/CD管道和docker构建!您还可以使用它一次性安装所有东西,而不是安装特定的软件包。
您链接的文档具有摘要:
简而言之,使用npm安装和npm配置项之间的主要区别是: