npm in node depends on the installation order, detailed explanation of package-lock.json file

Pre-knowledge: You need to understand the basic knowledge and usage of package.json and package-lock.json, you can refer to this article .

The logic and order of npm dependent installation can refer to this article

After reading the theory, let's take a look at the actual project. The logic mentioned in the above article will be displayed in the package-lock.json file after npm install.

Pre-knowledge

1. What is the difference between npm2 and npm3?

Haha, don't think too much, it is actually the version number of npm, npm2 is the 2.xx version of npm, and npm3 is the 3.xx version of npm. There is a big change from npm2 to npm3. As mentioned in the above article, 2 -> 3 is a very important dividing line, so you don’t often see npm4, npm5, etc., because the core logic has not changed much. .

Both npm and node versions correspond. Please refer to the official website of node . We often talk about the node version in our projects, so it is normal that you are not familiar with the npm version.

Ok, now let's continue to study the package-lock.json file. Please see the official document

The specific fields of lock files in different npm versions are different, but they are similar. We can know the meaning and structure of the key [dependencies] 

 Assuming that there is only one package in the project package.json, and this package has no sub-dependencies, it is very simple after install

Let's look at a complex one, such as the vue package

 Let's take a brief look at one by one

The first is a package with no sub-dependencies, which is obvious to install

The second type is @vue/compiler-dom with sub-dependencies, which will take out sub-dependencies [for example: @vue/compiler-core] and put them at the same level as @vue/compiler-dom, which is the above article The optimization of npm3 relative to npm2 avoids repeated installation of the same dependency. How is it very simple.

 

To sum up, we need to learn to read official documents. For example, the official websites of node and npm contain a lot of unfamiliar knowledge. Pay attention to the English version of the official website.

Node.jsNode.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.https://nodejs.org/ennpm DocsDocumentation for the npm registry, website, and command-line interfacehttps://docs.npmjs.com/

 

Guess you like

Origin blog.csdn.net/qq_17335549/article/details/130348630
Recommended