Basic usage of npm ci command

  • 2021-08-28 07:12:39
  • OfStack

Occasionally, I found that npm ci command feels much faster than npm i, so I also came to understand this command.

1. Purpose

npm ci and npm install commands, like 1, are used to install dependencies, but they can be much faster and more rigorous than regular npm installations, and they can be npm dependencies installed with 1 and stable (lock version).

In package. json, after each install, there is a ^ symbol before the corresponding version. In this case, when you re-install install, the package version may not be the same as the previous one. For details, you can check the actual package version in package-lock. json.

The matching rule for ^ is: > = Current version and maintains the first non-zero version from left to right. For example:

"^ 1.2. 3": Greater than or equal to 1.2. 3 and less than version 2.0. 0
"^ 0.3. 4": Greater than or equal to 0.3. 4 and less than version 0.4. 0
"^ 0.0. 6": greater than or equal to 0.0. 6 and less than 0.0. 7 version

If we use the install command directly, we will encounter the problem of different package versions during development, testing and release, and this subtle difference often leads to serious results.

2. Usage

Change to npm ci where npm i (install). Of course, there must be one package-lock. json or npm-shrinkwrap. json in the project.

Note: npm version should > = 5.7.

3. Difference

The main differences between npm ci and npm i are as follows.

npm i depends on package. json, while npm ci depends on package-lock. json. npm ci exits but does not modify package-lock. json when package. json dependency in package-lock. json is not 1. npm ci can only install an entire project dependency once, but cannot add a single dependency. npm ci will delete the node_modules folder before installing the package, so he does not need to verify the relationship between the downloaded file version and the control version, and does not need to verify whether the latest version of the library exists, so the download speed is faster. package. json and package-lock. json will not be modified when npm is installed.

The order was issued in February last year, but it is really shameful to know it now.

Summarize


Related articles: