2016-02-26 158 views
0

当我试图安装一个单独的模块到项目中,像一饮而尽,它安装所有node_module ...为什么NPM install安装所有node_modules

我不知道这些模块来的,我得到这样99文件夹放入node_modules文件夹中,当我只想安装一个。

+0

这不是真的。这只是吞噬需要的所有软件包。这是javascript开发的文化:开发人员编写小部分代码(有时非常小),易于维护,然后使用其他人员的代码来获取所需功能。开发人员没有浪费时间编写代码来打印颜色(他们使用粉笔)或编写代码来并行管理产卵任务(他们使用编排器)等等。所以吞咽依赖于13个包,它们本身依赖于更多的包等。 – slebetman

+0

[npm dependancies installation,confused]可能重复(https://stackoverflow.com/questions/31317925/npm-dependancies-installation-confused) –

回答

0

这是按设计。 @https://docs.npmjs.com/cli/install,总结为:该命令将安装一个软件包以及它所依赖的任何软件包。

这里是算法定义在页面:

load the existing node_modules tree from disk 
clone the tree 
fetch the package.json and assorted metadata and add it to the clone 
walk the clone and add any missing dependencies 
    dependencies will be added as close to the top as is possible 
    without breaking any other modules 
compare the original tree with the cloned tree and make a list of 
actions to take to convert one to the other 
execute all of the actions, deepest first 
    kinds of actions are install, update, remove and move 
相关问题