错误:捆绑包initial-es5超出了最大预算。预算 6.00 MB 未达到 133.51 kB,总共 6.13 MB

sav*_*eer 6 javascript bundle node-modules typescript angular

我有一个角度应用程序升级到 11。

\n

我做了一个> ng build --prod

\n

我看到这个信息:

\n
\xe2\x88\x9a Browser application bundle generation complete.\n\xe2\x88\x9a ES5 bundle generation complete.\n\nInitial Chunk Files                      | Names                |      Size\nscripts.3cf268d47c462590e7d9.js          | scripts              |   3.27 MB\nmain-es5.9973d9ddec6de2b044ba.js         | main                 |   2.49 MB\nmain-es2015.9973d9ddec6de2b044ba.js      | main                 |   2.36 MB\nstyles.d540d930321db4c962dc.css          | styles               | 245.64 kB\npolyfills-es5.259ae27e17f48bc03647.js    | polyfills-es5        | 131.80 kB\npolyfills-es2015.732b81c0b5a3e3dbb1bc.js | polyfills            |  36.16 kB\nruntime-es2015.a4dadbc03350107420a4.js   | runtime              |   1.45 kB\nruntime-es5.a4dadbc03350107420a4.js      | runtime              |   1.45 kB\n\n                                         | Initial ES5 Total    |   6.13 MB\n                                         | Initial ES2015 Total |   5.91 MB\n\nBuild at: 2021-02-18T14:49:39.581Z - Hash: 0e159b0e28a5a4f69881 - Time: 144004ms\n\n
Run Code Online (Sandbox Code Playgroud)\n

但我也收到此错误:

\n
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.\n\n
Run Code Online (Sandbox Code Playgroud)\n

但我前段时间已经改变了预算规模:

\n
 "budgets": [\n                {\n                  "type": "initial",\n                  "maximumWarning": "4mb",\n                  "maximumError": "6mb"\n                },\n                {\n                  "type": "anyComponentStyle",\n                  "maximumWarning": "6kb",\n                  "maximumError": "10kb"\n                }\n              ]\n\n
Run Code Online (Sandbox Code Playgroud)\n

当然,我可以再次增加尺寸。但当然,这不是您想要做的。

\n

这是我的 pacakge.json 文件:

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

如何减少dist文件夹?

\n

谢谢

\n

Dan*_* P. 6

有时,当您的应用程序增长时,没有其他选择,您必须提高 angular.json 中的批量大小限制才能进行编译。

但首先您应该尝试删除无用的代码、依赖项、资产、样式等,以减小大小。

另请检查这些提示:https://indepth.dev/posts/1217/how-to-reuse-common-layouts-in-angular-using-router