How to solve the problem of huge project volume caused by repeated installation of npm package?

  node.js, question

Problem description


As shown in the above figure, the project depends on 4 packages, but these 4 packages also depend on the same package at the same time, thus there will be repeated downloads and repeated dependencies.

As a result, the whole project package is very large. How can we solve this problem?

Volume comparison of NPM install in different versions

When only relying on chokidar, node-sass and uglify-js, NPM post-install comparison is performed.

Npm2install: 22,118,854 bytes
Dedupe after npm2 install: 16,834,945 bytes

Npm3install: 18,026,936 bytes
Dedupe after npm3 install: 15,366,266 bytes

Npm 3 will not have such a structure after that. Upgrade npm to 3, then delete node_modules and reinstall it again.