• Angular升级后运行编译变慢?如何解决?


            公司的Angular项目升级后,使用体验感十分不好,运行、编译的时间明显增长,工作效率是十分低下,但奈何公司的大佬们都有自己的事情要忙,结识的大佬也不够多,只能靠自己找度娘了。但是,哎,你还别说,真让我找到了!!!

    感谢下面这位大大的分享:解决在升级到Angular v13之后,ng serve启动变慢(slow)的问题_angular12编译慢-CSDN博客

            上面这位大大的分享中呢有一篇来自外国程序员的解释(https://dev.to/brandontroberts/speeding-up-the-development-serve-after-upgrading-to-angular-v12-5db5),大家有条件可以自行查看,不过个人觉得上面大大的文章已经十分详细了,完全足够!亲试有效!!!

    主要解决办法截图如下:再次感谢大大的分享!

            总结解决办法:添加development构建配置,也就是我们需要手动将开发选项添加为默认值,并将serve中target的defaultConfiguration设置为development

          注意按照上面截图改了之后初始运行整个项目的时间几乎没有太大改变,但是编译时间是有明显改善的!!!

          要想初始运行整个项目的时间也减少,需要进行下面的配置:

    1. "serve": {
    2. "builder": "@angular-devkit/build-angular:dev-server",
    3. + "defaultConfiguration": "",
    4. "options": {
    5. + "browserTarget": "ngv12:build:development"
    6. },
    7. "configurations": {
    8. "production": {
    9. "browserTarget": "ngv12:build:production"
    10. },
    11. + "development": {
    12. + "browserTarget": "ngv12:build:development"
    13. + }
    14. }
    15. }

    完整代码如下:

    1. {
    2. "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    3. "version": 1,
    4. "newProjectRoot": "projects",
    5. "projects": {
    6. "ngv12": {
    7. "projectType": "application",
    8. "schematics": {},
    9. "root": "",
    10. "sourceRoot": "src",
    11. "prefix": "app",
    12. "architect": {
    13. "build": {
    14. "builder": "@angular-devkit/build-angular:browser",
    15. "options": {
    16. "outputPath": "dist/ngv12",
    17. "index": "src/index.html",
    18. "main": "src/main.ts",
    19. "polyfills": "src/polyfills.ts",
    20. "tsConfig": "tsconfig.app.json",
    21. "assets": [
    22. "src/favicon.ico",
    23. "src/assets"
    24. ],
    25. "styles": [
    26. "src/styles.css"
    27. ],
    28. "scripts": []
    29. },
    30. "configurations": {
    31. + "development": {
    32. + "vendorChunk": true,
    33. + "extractLicenses": false,
    34. + "buildOptimizer": false,
    35. + "sourceMap": true,
    36. + "optimization": false,
    37. + "namedChunks": true
    38. + },
    39. "production": {
    40. "fileReplacements": [
    41. {
    42. "replace": "src/environments/environment.ts",
    43. "with": "src/environments/environment.prod.ts"
    44. }
    45. ],
    46. "optimization": true,
    47. "outputHashing": "all",
    48. "sourceMap": false,
    49. "namedChunks": false,
    50. "extractLicenses": true,
    51. "vendorChunk": false,
    52. "buildOptimizer": true,
    53. "budgets": [
    54. {
    55. "type": "initial",
    56. "maximumWarning": "2mb",
    57. "maximumError": "5mb"
    58. },
    59. {
    60. "type": "anyComponentStyle",
    61. "maximumWarning": "6kb",
    62. "maximumError": "10kb"
    63. }
    64. ]
    65. }
    66. },
    67. + "defaultConfiguration": "production"
    68. },
    69. "serve": {
    70. "builder": "@angular-devkit/build-angular:dev-server",
    71. + "defaultConfiguration": "",
    72. "options": {
    73. + "browserTarget": "ngv12:build:development"
    74. },
    75. "configurations": {
    76. "production": {
    77. "browserTarget": "ngv12:build:production"
    78. },
    79. + "development": {
    80. + "browserTarget": "ngv12:build:development"
    81. + }
    82. }
    83. }
    84. }
    85. }
    86. },
    87. "defaultProject": "ngv12"
    88. }
  • 相关阅读:
    聚观早报 | 东方甄选推出独立 App;腾讯《冒险岛 2》即将停服
    深入理解面向对象(第二篇)
    Qt扩展-KDDockWidgets 的使用
    Linux.系统命令
    具有用于外部阻断 FET 的驱动器TPS259240DRCR
    你应该知道的 7 个很棒的 Java 项目
    python图片压缩/格式转换
    Docker容器
    Linux文件/目录所属组修改
    灯塔批量添加指纹信息
  • 原文地址:https://blog.csdn.net/qq_44327851/article/details/136221432