gpt4 book ai didi

javascript - Angular-cli : Launch time is too slow

转载 作者:行者123 更新时间:2023-12-01 03:54:46 25 4
gpt4 key购买 nike

需要改进我的 Angular2 应用程序启动时间。默认情况下,启动需要 10-12 秒。

应用程序中有多个模块,每个模块都是使用延迟加载的方式加载的。

这是我的 package.json 文件

{
"name": "AppStore-cli",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.3.1",
"@angular/compiler": "2.3.1",
"@angular/core": "2.3.1",
"@angular/forms": "2.3.1",
"@angular/http": "2.3.1",
"@angular/material": "2.0.0-beta.1",
"@angular/platform-browser": "2.3.1",
"@angular/platform-browser-dynamic": "2.3.1",
"@angular/router": "3.3.1",
"@types/file-saver": "0.0.0",
"angular2-moment": "1.2.0",
"angular2-select": "1.0.0-beta.3",
"autotable": "1.0.0",
"core-js": "2.4.1",
"file-saver": "^1.3.3",
"jspdf": "1.3.2",
"jspdf-autotable": "2.3.1",
"md2": "0.0.16",
"ng2-auto-complete": "0.10.9",
"ng2-pagination": "2.0.0",
"ng2-slimscroll": "1.2.1",
"ng2-toastr": "1.4.1",
"rxjs": "5.0.1",
"ts-helpers": "1.1.1",
"zone.js": "0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "2.3.1",
"@types/file-saver": "0.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "6.0.42",
"angular-cli": "1.0.0-beta.28.3",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "2.0.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.0.2",
"karma-remap-istanbul": "0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "4.3.0",
"typescript": "~2.0.3"
}
}

angular-cli.json

{
"project": {
"version": "1.0.0-beta.28.3",
"name": "AppStore-cli"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
"./images/"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"styles": [
"styles.css",
"css/indigo-pink.css",
"css/admin.css",
"../node_modules/ng2-toastr/bundles/ng2-toastr.min.css"
],
"scripts": [
"../node_modules/core-js/client/shim.min.js",
"../node_modules/reflect-metadata/Reflect.js",
"../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"files": "src/**/*.ts",
"project": "src/tsconfig.json"
},
{
"files": "e2e/**/*.ts",
"project": "e2e/tsconfig.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}

我正在使用以下命令进行构建

ng build --prod

这是构建完成后生成的文件的屏幕排序。

enter image description here这是加载时间的屏幕排序。

enter image description here

任何人都可以帮助我如何将启动时间减少到 2-3 秒或更少?

谢谢

最佳答案

您可以做的事情很少:

  • 运行ng build -prod -aot --stats-json
  • 修复您可能遇到的任何错误(并重建)
  • 安装webpack-bundle-analyze npm install --save-dev webpack-bundle-analyzer
  • 运行webpack-bundle-analyzer dist/stats.json
  • 查看您的 bundle 并删除任何不必要的代码
  • 在您的服务器上安装压缩 ( gzip )(仅此一项就可以将 vendor bundle 减少到约 400kb)

如果速度仍然很慢,请使用通用、服务和网络工作人员研究服务器端渲染...Google 可以提供帮助(;

还考虑升级到 Angular 4.0.0 。它生成的代码少于 2.x.x .

关于javascript - Angular-cli : Launch time is too slow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42860225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com