javascript - 错误 : bundle initial-es5 exceeded maximum budget. 预算 6.00 MB 未满足 133.51 kB 总共 6.13 MB

标签 javascript angular typescript bundle node-modules

我有一个升级到 11 的 Angular 应用程序。
我做了一个> ng build --prod我看到了这些信息:

√ Browser application bundle generation complete.
√ ES5 bundle generation complete.

Initial Chunk Files                      | Names                |      Size
scripts.3cf268d47c462590e7d9.js          | scripts              |   3.27 MB
main-es5.9973d9ddec6de2b044ba.js         | main                 |   2.49 MB
main-es2015.9973d9ddec6de2b044ba.js      | main                 |   2.36 MB
styles.d540d930321db4c962dc.css          | styles               | 245.64 kB
polyfills-es5.259ae27e17f48bc03647.js    | polyfills-es5        | 131.80 kB
polyfills-es2015.732b81c0b5a3e3dbb1bc.js | polyfills            |  36.16 kB
runtime-es2015.a4dadbc03350107420a4.js   | runtime              |   1.45 kB
runtime-es5.a4dadbc03350107420a4.js      | runtime              |   1.45 kB

                                         | Initial ES5 Total    |   6.13 MB
                                         | Initial ES2015 Total |   5.91 MB

Build at: 2021-02-18T14:49:39.581Z - Hash: 0e159b0e28a5a4f69881 - Time: 144004ms

但我也收到此错误:
Error: bundle initial-es5 exceeded maximum budget. Budget 6.00 MB was not met by 133.51 kB with a total of 6.13 MB.

但我前段时间已经更改了预算大小:
 "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "4mb",
                  "maximumError": "6mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]

当然,我可以再次增加尺寸。但是,当然,这不是您想要做的。
这是我的 pacakge.json 文件:
{
  "name": "dashboard-frontend",
  "version": "0.0.0",
  "sideEffects": false,
  "scripts": {
    "ng": "ng",
    "start": "ng serve -o",
    "build": "ng build --stats.json --prod=true --deleteOutputPath=false",
    "test": "ng test",
    "lint": "npm run lint.eslint && npm run lint.prettier && npm run lint.types",
    "lint.eslint": "eslint . --ext ts",
    "lint.prettier": "prettier -c src/**/*.ts",
    "lint.types": "tsc --noEmit",
    "e2e": "ng e2e"
  },
  "private": true,
  "browser": {
    "fs": false,
    "path": false,
    "os": false
  },
  "dependencies": {
    "@angular-material-components/datetime-picker": "^5.0.3",
    "@angular-devkit/build-angular": "^0.1102.1",
    "@angular/animations": "~11.2.1",
    "@angular/cdk": "10.2.7",
    "@angular/common": "~11.2.1",
    "@angular/compiler": "~11.2.1",
    "@angular/core": "~11.2.1",
    "@angular/elements": "11.2.1",
    "@angular/forms": "~11.2.1",
    "@angular/material": "10.2.7",
    "@angular/material-moment-adapter": "^11.2.0",
    "@angular/platform-browser": "~11.2.1",
    "@angular/platform-browser-dynamic": "~11.2.1",
    "@angular/router": "~11.2.1",
    "@fortawesome/angular-fontawesome": "0.7.0",
    "@fortawesome/fontawesome-svg-core": "1.2.30",
    "@fortawesome/free-solid-svg-icons": "5.14.0",
    "@mapbox/mapbox-gl-geocoder": "4.7.0",
    "@types/jest": "^26.0.15",
    "@types/mocha": "^8.0.4",
    "angular-auth-oidc-client": "^11.2.0",
    "angular-gridster2": "10.1.6",
    "angular-plotly.js": "3.0.0",
    "bootstrap": "4.5.2",
    "bootstrap-icons": "1.3.0",
    "idb": "6.0.0",
    "jasmine": "^3.6.3",
    "jest": "^26.6.3",
    "luxon": "1.25.0",
    "mapbox-gl": "^1.12.0",
    "material-icons": "^0.3.1",
    "moment": "^2.29.1",
    "ngx-mapbox-gl": "4.8.1",
    "plotly.js": "1.55.2",
    "rxjs": "~6.5.4",
    "ts-jest": "^26.4.4",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1102.1",
    "@angular/cli": "~11.2.1",
    "@angular/compiler-cli": "~11.2.1",
    "@angular/language-service": "~11.2.1",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/luxon": "1.25.0",
    "@types/mapbox-gl": "1.12.5",
    "@types/node": "^12.12.62",
    "@types/plotly.js": "^1.50.21",
    "@typescript-eslint/eslint-plugin": "^4.4.1",
    "@typescript-eslint/parser": "^4.4.1",
    "eslint": "^7.11.0",
    "eslint-config-google": "^0.14.0",
    "eslint-config-prettier": "^6.13.0",
    "eslint-plugin-prettier": "^3.1.4",
    "gzipper": "^4.4.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.1.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "prettier": "^2.1.2",
    "prettier-eslint": "^11.0.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.0.5"
  }
}


如何减少 dist 文件夹?
谢谢

最佳答案

有时,当您的应用程序增长时,没有其他选择,您必须提高 angular.json 中的批量大小限制才能编译。
但首先您应该尝试删除无用的代码、依赖项、 Assets 、样式等,以减小大小。
另请查看以下提示:https://indepth.dev/posts/1217/how-to-reuse-common-layouts-in-angular-using-router

关于javascript - 错误 : bundle initial-es5 exceeded maximum budget. 预算 6.00 MB 未满足 133.51 kB 总共 6.13 MB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66263285/

相关文章:

angular - RXJS 运算符(operator)不使用 firebase

Angular 11 : subscribe is deprecated: Use an observer instead?

javascript - 自然窗口调整大小事件会使 Chrome 中的布局无效,而强制窗口调整大小则不会。

javascript - Object.keys() 返回在 Ant Design 表列渲染中不起作用

Javascript:使用 DOM 和 join()

angular - 一个模块下可以添加多少个组件?

javascript - Angular : How to show icon. png 取决于项目的属性?

javascript - 无法在 routerOnActivate 上获取查询参数

javascript - 数字中的前导和尾随零

javascript - Typescript 无法解析 json 文件?