ng build --prod does NOT minify / uglify / remove comments since Angular CLI 6

前端 未结 1 1109
孤街浪徒
孤街浪徒 2020-12-31 15:27

Since I\'ve upgraded my Angular app to use Angular CLI version 6.x, compiling it for production (using ng build --prod, as usual) does not produce

相关标签:
1条回答
  • 2020-12-31 15:55

    The issue is in angular.json file.

    Under the key projects.MY_PROJECT_NAME.architect.build.configurations.production, I was missing all the options that normally comes by default in the production configuration when you create a new angular project.

    This is how the production configuration should look like in order to fix the issue:

    "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
    },
    

    For some reasons, after upgrading from previous Angular CLI versions, my production configuration only had the fileReplacements key. Adding the other properties shown above (optimization, outputHashing, etc...) solved the issue for me.

    0 讨论(0)
提交回复
热议问题