node.js “npm install” 在 node_modules 目录中安装所有依赖项,而不是将它们嵌套
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33154836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"npm install" installs all dependencies in node_modules directory, instead of having them nested
提问by LoveAndHappiness
I need to know if the following behavior is normal.
我需要知道以下行为是否正常。
When I npm install, each package from my package.jsonand the dependencies, don't get installed nestedanymore, but each dependency is installed in the node_modulesdirectory. That makes my node_modulesdirectory blown and look like this:
当我npm install,我的package.json 中的每个包和依赖项不再嵌套安装,但每个依赖项都安装在node_modules目录中。这让我的node_modules目录爆炸,看起来像这样:
This happened since I updated npm and node.
这是因为我更新了 npm 和 node.js。
Now I run:
现在我运行:
npm -v 3.3.6
node -v 4.2.1
python 2.7
windows 7
wamp
My package.jsonfile looks like this:
我的package.json文件看起来像这样:
{
"private": true,
"devDependencies": {
"gulp": "^3.8.8"
},
"dependencies": {
"laravel-elixir": "^3.0.0",
"bootstrap-sass": "^3.0.0"
}
}
It's the standard laravel package.jsonfile.
这是标准的 Laravelpackage.json文件。
Is there a way to have nested directories again, because I don't like such a blown article with over 100 sub directories.
有没有办法再次嵌套目录,因为我不喜欢这种有 100 多个子目录的文章。
采纳答案by sagie
That's the newbehavior of npm 3as per this npm blog.
这是根据这个 npm blog的新行为。npm 3
回答by luchaos
Update:As Erik Pukinskis mentioned in the comments:
As of npm 3.5, support for --legacy-bundlinghas been dropped.
更新:正如 Erik Pukinskis 在评论中提到的那样:从 npm 3.5 开始,--legacy-bundling已经取消了对 的支持。
Yes, there is a way to have nested directories again by changing npm's (version 3 as of this writing) default behaviour:
是的,有一种方法可以通过更改 npm(撰写本文时的版本 3)的默认行为来再次拥有嵌套目录:
Delete the currently present
node_modulesfolder.Tell npm to install with legacy bundling for this one install:
npm install --legacy-bundling
删除当前存在的
node_modules文件夹。告诉 npm 使用旧版捆绑来安装此安装:
npm install --legacy-bundling
A "permanent" alternative:
“永久”替代方案:
Set your npm config to always use legacy bundling...
npm set legacy-bundling=true.. and run as usual:
npm install
将您的 npm 配置设置为始终使用旧版捆绑...
npm set legacy-bundling=true..并像往常一样运行:
npm install
Note:fetching dependencies with legacy bundling will take a lot more time because many several different versions of the same dependencies will be installed.
注意:使用遗留捆绑获取依赖项将花费更多时间,因为将安装相同依赖项的许多不同版本。
Disclaimer:As a non-Windows user I have no need for flat dependencies and want to find self-declared dependencies with ease in favour of automatic deduping. Since installing npm dependencies without legacy bundling already takes an incredible amount of time I'm usually willing to spend those extra minutes install time. It gets back down to 5 directories from previously 700+ (...) in a Laravel Elixir setup with bootstrap (non-sass), font-awesome and jquery added.
免责声明:作为非 Windows 用户,我不需要平面依赖项,并希望轻松找到自我声明的依赖项以支持自动重复数据删除。由于在没有遗留捆绑的情况下安装 npm 依赖项已经花费了令人难以置信的时间,我通常愿意花费这些额外的几分钟安装时间。在 Laravel Elixir 设置中,它从之前的 700+ (...) 个目录减少到 5 个目录,并添加了 bootstrap(非 sass)、font-awesome 和 jquery。


