In NPMv2, node_modules has a nested topology for each package.
Assumptions:
- Project depend on
package-a
与package-b
Two package package-a
与package-b
The dependence of[email protected]
- package-a
- package-b
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
- Nested too deeply
- 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?
- package-a
- package-b
Graph app (node_modules) -- - > A app (package - A) -- - > B (package - B) app - > C (" [email protected] ") -- - > D (" [email protected] ")
- Package-b starts with node_modules
lodash
To find[email protected]
One more question: what’s the final node_modules result so far
- package-a
- package-b
- package-c
- package-d
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] ")
- Package-d can only find [email protected] from its own node_modules, not from package-c, in which case [email protected] will inevitably be installed twice
What’s wrong with duplicate version dependencies?
- Install Size, the installation volume becomes large, wasting disk space
- Build Size, waste bandwidth, site opening delays, and ruin user experience.
- 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