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.
所以例如如果软件包A依赖于软件包B,当你安装npm时你会得到这个文件结构:
--- root/ |--- node_modules/ |--- A/ |--- B/
而不是版本2或更低版本的旧文件结构:
--- root/ |--- node_modules/ |--- A/ |--- node_modules/ |--- B/
第一个(我肯定不是最后一个)我遇到的问题是这样的:
软件包A不知道npm v3的行为,并且取决于软件包B.但是,A假定旧(v2)文件结构,因为它的代码中具有node_modules / B,而不是正确的../node_modules/B.现在来自A的代码不会编译,因为它正在找错误的目录中的B /.
如果我不想让开发人员修改代码并等待A的更新,我想知道是否有一种方法可以设置一个选项,这将强制npm将A的依赖项安装在自己的node_modules文件夹中,同样的方式npm v2将会做到这一点.
https://docs.npmjs.com/cli/install
The –legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4,such as the one included with node 0.8,can install the package. This eliminates all automatic deduping.