简体   繁体   English

“npm install” 在 node_modules 目录中安装所有依赖项,而不是将它们嵌套

[英]“npm install” installs all dependencies in node_modules directory, instead of having them nested

I need to know if the following behavior is normal.我需要知道以下行为是否正常。

When I npm install , each package from my package.json and the dependencies, don't get installed nested anymore, but each dependency is installed in the node_modules directory.当我npm install ,我的package.json 中的每个包和依赖项不再嵌套安装,但每个依赖项都安装在node_modules目录中。 That makes my node_modules directory blown and look like this:这使我的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.json file 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.json file.这是标准的 laravel package.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 多个子目录的文章。

Update: As Erik Pukinskis mentioned in the comments: As of npm 3.5, support for --legacy-bundling has 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)的默认行为来再次嵌套目录:

  1. Delete the currently present node_modules folder.删除当前存在的node_modules文件夹。

  2. Tell npm to install with legacy bundling for this one install:告诉 npm 使用旧版捆绑来安装此安装:

    npm install --legacy-bundling

A "permanent" alternative: “永久”替代方案:

  1. Set your npm config to always use legacy bundling...将您的 npm 配置设置为始终使用旧版捆绑...

    npm set legacy-bundling=true

  2. .. and run as usual: ..并像往常一样运行:

    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.免责声明:作为非 Windows 用户,我不需要平面依赖项,并希望轻松找到自我声明的依赖项以支持自动重复数据删除。 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.由于在没有遗留捆绑的情况下安装 npm 依赖项已经花费了令人难以置信的时间,我通常愿意花费这些额外的几分钟安装时间。 It gets back down to 5 directories from previously 700+ (...) in a Laravel Elixir setup with bootstrap (non-sass), font-awesome and jquery added.在 Laravel Elixir 设置中,它从之前的 700+ (...) 个目录减少到 5 个目录,并添加了 bootstrap(非 sass)、font-awesome 和 jquery。

这是npm 3根据此 npm blog行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM