【问题标题】:How to tell if I really need the number of Node packages that have downloaded?如何判断我是否真的需要已下载的 Node 包的数量?
【发布时间】:2018-01-20 05:37:18
【问题描述】:

我正在使用 Angular 和 ngx-bootstrap,但我在 node_modules 中有 269 个文件夹。当然不是所有这些都是必要的吗?有没有办法确定这 269 个文件夹中的一些是否不再需要? node_modules 文件夹超过 88MB!在过去的几天里,我可能已经安装了一些其他软件包,但我不记得了,因为我还必须手动调整我的 package.json 文件。

这是我的 package.json

{
  "author": "me",
  "dependencies": {
    "@angular/cdk": "^2.0.0-beta.8",
    "@angular/common": "~4.3.0",
    "@angular/compiler": "~4.3.0",
    "@angular/core": "~4.3.0",
    "@angular/forms": "~4.3.0",
    "@angular/http": "~4.3.0",
    "@angular/platform-browser": "~4.3.0",
    "@angular/platform-browser-dynamic": "~4.3.0",
    "@angular/router": "~4.3.0",
    "angular-in-memory-web-api": "~0.2.4",
    "core-js": "^2.5.0",
    "moment": "^2.18.1",
    "moment-timezone-all": "^0.5.5",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.8.4"
  },
  "description": "A starter app using Angular2, Bootstrap CSS for hosting within an ASP.NET MVC web app",
  "devDependencies": {
    "@types/node": "^6.0.85",
    "alertify.js": "^1.0.12",
    "bootstrap": "^3.3.7",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "modernizr": "^3.5.0",
    "ngx-bootstrap": "^1.8.1",
    "systemjs": "^0.19.40"
  },
  "keywords": [],
  "license": "MIT",
  "name": "aspng2",
  "repository": {},
  "version": "1.0.0"
}

【问题讨论】:

  • 你可以试试npm prune(见stackoverflow.com/questions/21417014/…),但现实情况是,像Angular这样的框架非常庞大,而JavaScript生态系统现在也非常庞大,所以你很有可能无法做到完全节省空间。
  • ^ 这应该是答案。 npm prune。 '269' 看起来并不太奇怪,因为 NPM 3 及更高版本具有简单的目录结构。对于 Angular 项目,88MB 被认为很小。

标签: angular npm


【解决方案1】:

如果您使用 Angular CLI 并使用它的 ng build --prod,它将为您执行某种程度的“摇树”。这意味着它将删除这些供应商功能中未使用的部分,从而使您部署的包显着变小。

有关详细信息,请参阅此处的文档:https://angular.io/guide/aot-compiler#tree-shaking

【讨论】:

    猜你喜欢
    • 2020-09-21
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2012-07-11
    相关资源
    最近更新 更多