我注意到npm在不同模块需要它们时会多次安装相同的node.js软件包。
是否可以关闭此选项并为所有软件包提供一个回购协议?
我看了一下,但没有找到任何东西。
This is the default behaviour of NPM since version 3. Quoting the changelog of that version:
Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's
node_modules
folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.
As you can see, if you have modules which have conflicting dependencies (i.e. require different versions of the same dependency), multiple versions of such dependencies will be installed, and this cannot be avoided.
如果您怀疑node_modules
目录以某种方式包含重复项,则可以使用命令npm dedupe
(docs)查找重复项并减少重复项,每个重复项仅保留一个实例。