In NPMv2, node_modules has a nested topology for each package.

Assumptions:

  1. Project depend onpackage-apackage-bTwo package
  2. package-apackage-bThe dependence of[email protected]

The node_modules directory structure is as follows:

Graph app (node_modules) -- - > A app (package - A) -- - > B (package - B) A - > C (" [email protected] ") -- - > D (" [email protected] ")

The biggest problem at this point

  1. Nested too deeply
  2. Taking up too much space

Tile structure

Node_modules is tiled after nPMv3, and the topology is as follows:

Graph app (node_modules) -- - > A app (package - A) -- - > B (package - B) app - > C (" [email protected] ")

One question: what is the final node_modules result of the following dependencies?

  • package-a
    • Lodash @ ^ 4.17.4
  • package-b
    • Lodash @ ^ 4.16.1

A: Consistent with the above topology, because they are ^ versions, they will both download the latest version that matches the range of versions, such as @4.17.4, so they depend on the same

If there is a lock, there will be a small problem, which will be discussed later

Graph app (node_modules) -- - > A app (package - A) -- - > B (package - B) app - > C (" [email protected] ")

One more question: what is the final node_modules result of the following dependencies?

Graph app (node_modules) -- - > A app (package - A) -- - > B (package - B) app - > C (" [email protected] ") -- - > D (" [email protected] ")

One more question: what’s the final node_modules result so far

graph app(node_modules) ---> A(package-a) app ---> B(package-b) app ---> C(package-c) app ---> D(package-d) app ---> X (" [email protected] ") C - > Y (" [email protected] ") D - > Z (" [email protected] ")

What’s wrong with duplicate version dependencies?

  1. Install Size, the installation volume becomes large, wasting disk space
  2. Build Size, waste bandwidth, site opening delays, and ruin user experience.
  3. Break the singleton pattern and break the cache, as many plug-ins of PostCSS throw PostCSS into Dependencies, and repeated versions will cause the AST to be parsed multiple times