Minify / Uglify / remove comments your final Angular build

Removing unwanted code and minifying your application is a crucial step before pushing to production.

To fix this, just open up angular.json config file in your editor and navigate to 

Projects” > “Name Of Your Angular App” > “architect” > “configurations” > “production

        "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,
             "budgets": [
               {
                 "type": "initial",
                 "maximumWarning": "2mb",
                 "maximumError": "5mb"
               },
               {
                 "type": "anyComponentStyle",
                 "maximumWarning": "6kb",
                 "maximumError": "10kb"
               }
             ]

By setting the “optimization” to true, “vendorChunk” to true and “aot” to true set’s the build to have optimised results.

Finally, perform linting before the build to remove any unwanted logical code in your application.

ALSO READ  Angular 6 - Routing and Navigation (with Child Routes & Route Auth Guards)