如何提高Angular的编译速度

时间:2020-06-18 04:42:50

标签: angular typescript development-environment

如何在Angular中更快地编译?通常,我的项目只需要更新一次代码就需要617794ms。这是我的日志:

enter image description here

This is my angular.json

=========================   angular.json ========================

{ “ $ schema”:“ ./ node_modules/@angular/cli/lib/config/schema.json”, “版本”:1, “ newProjectRoot”:“项目”, “项目”:{ “ hypeProject”:{ “根”: ””, “ sourceRoot”:“ src”, “ projectType”:“应用程序”, “ prefix”:“ app”, “示意图”:{

  },
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/hypeProject",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          {
            "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
          },
          "src/styles.css",
          "node_modules/datatables.net-dt/css/jquery.dataTables.css",
          "src/app/_content/app.less",
          "src/app/_content/modal.less"
        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.js",
         "node_modules/datatables.net/js/jquery.dataTables.js"
        ]
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true
        },
        "dev": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.dev.ts"
            }
          ],
          "optimization": false,
          "outputHashing": "all",
          "sourceMap": true,
          "extractCss": false,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": false,
          "vendorChunk": false,
          "buildOptimizer": false
        },
        "local": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.local.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true
        }
      }
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "hypeProject:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "hypeProject:build:production"
        },
        "dev": {
          "browserTarget": "hypeProject:build:dev"
        },
        "local": {
          "browserTarget": "hypeProject:build:local",
          "port": 8200,
          "host": "localhost"

        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "hypeProject:build"
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.spec.json",
        "karmaConfig": "src/karma.conf.js",
        "styles": [
          {
            "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
          },
          "src/styles.css"
        ],
        "scripts": [],
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ]
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "src/tsconfig.app.json",
          "src/tsconfig.spec.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
},
"danaonline-e2e": {
  "root": "e2e/",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "e2e/protractor.conf.js",
        "devServerTarget": "hypeProject:serve"
      },
      "configurations": {
        "production": {
          "devServerTarget": "hypeProject:serve"
        },
        "dev": {
          "devServerTarget": "hypeProject:serve"
        },
        "local": {
          "devServerTarget": "hypeProject:serve"
        }
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": "e2e/tsconfig.e2e.json",
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
}

}, “ defaultProject”:“ hypeProject” }

1 个答案:

答案 0 :(得分:0)

根据您的屏幕快照,看来您正在使用buildOptimization,这花费了太多时间,请将这些属性添加到angular.json中的构建配置中:

   "local": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.local.ts"
            }
          ],
          "optimization": false,
          "outputHashing": "all",
          "sourceMap": true,
          "extractCss": false,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": false,
          "vendorChunk": false,
           "buildOptimizer": false
     }
相关问题