我已经更新了我在 grunt 项目中使用的 node/npm。
但是,当我现在想将包添加到项目 myproject/
时(比如 npm install grunt-favicon
),它似乎向 添加了数百个文件夹myproject/node_modules/
而它只用于添加一个 - 通常以 grunt 为前缀,例如 node_modules/grunt-favicon
。
我对这些东西的了解是基本的,但这些似乎是必需的依赖项,甚至其中一些项目有更多的依赖项。
不应该在其他地方添加这些依赖项吗?如果是这样,我该如何纠正?
我使用 npm 3.3.5
、node 4.1.1
、grunt-cli v0.1.13
和 grunt v0.4.5
.
这个截图显示左侧是 ~/.npm
,右侧是 ~/myproject/node_modules
最佳答案
这是正确的,不要担心。您仍在本地安装软件包,只是目录结构看起来有点不同。这是 在 npm v3.0.0 中改变的行为:现在所有依赖项的依赖项都直接安装在 node_modules
文件夹中(只要这不会导致版本冲突)。这大大减小了文件树的大小。
Flat, flat, flat!
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.
关于node.js - 为什么安装一个 npm 包会在 node_modules 中添加许多子文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32951150/