Angular 5 Main js捆绑文件太大,加载应用程序需要30秒

时间:2018-05-03 10:45:55

标签: angular optimization webpack deployment angular-cli

我已尝试并通过stackoverflow和github问题讨论提出了许多答案,但我无法减少主捆绑文件的大小。我的包json文件如下所示:

"dependencies": {
"@angular/animations": "^5.2.2",
"@angular/common": "5.0.1",
"@angular/compiler": "5.0.1",
"@angular/core": "5.0.1",
"@angular/forms": "5.0.1",
"@angular/http": "5.0.1",
"@angular/platform-browser": "5.0.1",
"@angular/platform-browser-dynamic": "5.0.1",
"@angular/router": "5.0.1",
"@angular/upgrade": "5.0.1",
"@types/file-saver": "^1.3.0",
"chart.js": "2.7.1",
"compression": "^1.7.2",
"core-js": "2.5.1",
"rxjs": "5.5.2",
"ts-helpers": "1.1.2",
"zone.js": "0.8.18"
},

而开发依赖是:

"devDependencies": {
"@angular/cli": "^1.7.4",
"@angular/compiler-cli": "5.0.1",
"@types/jasmine": "2.6.3",
"@types/jquery": "^3.3.1",
"@types/node": "8.0.50",
"codelyzer": "4.0.1",
"jasmine-core": "2.8.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "1.7.1",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "1.3.0",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "0.2.2",
"protractor": "5.2.0",
"ts-node": "3.3.0",
"tslint": "5.8.0",
"typescript": "^2.4.2"
},

使用 ng build 我使用 ng build --prod 捆绑文件,同时使用 ng build --prod 将捆绑文件大小减少到 3.2 MB 即可。 我也尝试了不同的标志,比如-build-optimizer和-vendor-chunk = false以及--aot标志,虽然我认为angular 5默认包含所有这些,但没有任何改变,但文件对于生产来说太大了,它需要大约30加载应用程序的秒数。

0 个答案:

没有答案