angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

After upgrading to Angular 8 , compile time increased 3 times.

Open alialtun14 opened this issue 7 years ago • 26 comments

I upgraded my project to Angular 8 version. While upgrading process, I haven't met any error. But the compile time increased 3 times without any error.

Last Compile Before Angular 8  (with Angular 7.2)
Time: 1382.536ms -> main.cf29a89468d732f3f363.js (main) 12.4 MB 

First Compile After Upgrading to Angular 8
Time: 6379.317ms -> main.da4147c72278bc767ee4.js (main) 12.3 MB 

Second Compile After Upgrading to Angular 8 and After restart PC 
Time: 3147.254ms -> main.da4147c72278bc767ee4.js (main) 12.3 MB

tsconfig.json

{
 "compileOnSave": false,
 "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "./",
    "moduleResolution": "node",
    "outDir": "../__dist_cli",
    "sourceMap": true, 
    "target": "es5 ", 
    "module": "es2015",
    "lib": [
        "es2016",
        "dom"
    ],
    "typeRoots": [
        "node_modules/@types",
        "typings/custom"
    ]
}

package.josn

   ....
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.0.0",
    "@angular/cdk": "^8.0.0",
    "@angular/common": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/flex-layout": "^8.0.0-beta.26",
    "@angular/forms": "^8.0.0",
    "@angular/material": "^8.0.0",
    "@angular/platform-browser": "^8.0.0",
    "@angular/platform-browser-dynamic": "^8.0.0",
    "@angular/router": "^8.0.0",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "intl": "^1.2.5",
    "rxjs": "^6.5.2",
    "tar": "^4.4.8",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.800.0",
    "@angular-devkit/build-optimizer": "^0.800.0",
    "@angular/cli": "^8.0.0",
    "@angular/compiler": "^8.0.0",
    "@angular/compiler-cli": "^8.0.0",
    "@types/angular": "^1.6.54",
    "@types/angular-route": "^1.3.5",
    "@types/quill": "^2.0.2",
    "hammerjs": "^2.0.8",
    "quill": "^1.3.6",
    "typescript": "^3.4.5"
  }
}
Angular CLI: 8.0.0
Node: 12.3.1
OS: win32 x64
Angular: 8.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.0
@angular-devkit/build-angular     0.800.0
@angular-devkit/build-optimizer   0.800.0
@angular-devkit/build-webpack     0.800.0
@angular-devkit/core              8.0.0
@angular-devkit/schematics        8.0.0
@angular/flex-layout              8.0.0-beta.26
@ngtools/webpack                  8.0.0
@schematics/angular               8.0.0
@schematics/update                0.800.0
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

alialtun14 avatar May 31 '19 02:05 alialtun14

It is actually faster than in Angular 7. The difference is that Angular 8 provides Differential Loading out-of-the-box. In my case, it was compiling two different versions, one for es5 and other one for es2015, doubling the compilation process.

adripanico avatar Jul 23 '19 15:07 adripanico

I would like to thank everyone who helped solve the problem. Today we have launched the application compiled with angular 8.

alialtun14 avatar Aug 13 '19 22:08 alialtun14

It is actually faster than in Angular 7. The difference is that Angular 8 provides Differential Loading out-of-the-box. In my case, it was compiling two different versions, one for es5 and other one for es2015, doubling the compilation process.

How do you disable this?

metallidevils avatar Aug 19 '19 20:08 metallidevils

It is actually faster than in Angular 7. The difference is that Angular 8 provides Differential Loading out-of-the-box. In my case, it was compiling two different versions, one for es5 and other one for es2015, doubling the compilation process.

How do you disable this?

You have two choices:

  • To keep the differential loading feature and configure the browserlist file so your output target is only es5.
  • To completely disable differential loading.

Complete guide is provided by official Angular docs: https://angular.io/guide/deployment#configuring-differential-loading

More info: https://stackoverflow.com/questions/56197896/how-to-turn-off-differential-loading-in-angular-v8

Hope this help.

adripanico avatar Aug 20 '19 07:08 adripanico

There is a new Angular 8 feature called differential loading. To support differential loading, Angular 8 would build two bundles of JavaScript files, one set to support modern browers, the other set to support legacy browsers. Hence, it takes at least twice the build time as before.

In Angular 7, there used to have a setting in angular.json file, which specifies whether support es5 browsers or not.

angular.json

"build": {
    "es5BrowserSupport":  false
}

However, in Angular 8 this setting is deprecated. Instead, you have to configure browserslist file to tell Angular build which browsers are supported. By default, browserslist looks like below:

browserslist

0.5%              # It says: I want to support all browsers that have at least .05% of the global browser usage.
                  # So this will include some really old browsers.
last 2 versions   # It says: the last 2 versions for each browser, even mobile browsers. But our app is not targeting at mobile devices.
Firefox ESR       # the latest [Firefox ESR] version.
not dead          # Don't support outdated browsers
not IE 9-11       # Don't support IE 9 - 11

If you only care about Edge, Firefox and Chrome, drop 0.5% and last 2 versions, one will include very old browsers, the other will include all of the mobile browsers.

yuezhizizhang avatar Aug 29 '19 02:08 yuezhizizhang

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.