search

Home  >  Q&A  >  body text

javascript - 如何解决npm包重复安装,导致项目体积巨大的问题?

问题描述

如上图,项目依赖4个包,但这4个包又同时依赖同样的包,就会出现重复下载,重复依赖

导致整个项目包很大,该如何解决这个问题?


不同版本NPM install后体积对比

在仅依赖chokidar、node-sass、uglify-js时,执行npm install后对比

npm2 install:22,118,854 字节
npm2 install后dedupe:16,834,945 字节

npm3 install:18,026,936 字节
npm3 install后dedupe:15,366,266 字节

PHP中文网PHP中文网2817 days ago428

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-10 17:37:23

    npm 3以后就不是这样的结构了,升级npm到3,然后删除node_modules,重新安装一遍。

    reply
    0
  • 黄舟

    黄舟2017-04-10 17:37:23

    2到3是有改变,参考https://docs.npmjs.com/how-np...

    reply
    0
  • ringa_lee

    ringa_lee2017-04-10 17:37:23

    To get rid of duplication, we can run:

    npm dedupe

    reply
    0
  • 迷茫

    迷茫2017-04-10 17:37:23

    The packages marked in your screenshot should be considered as different packages although with same the same package name "async". Because these packages are of different versions.

    reply
    0
  • Cancelreply