angular / zone.js

Implements Zones for JavaScript
https://github.com/angular/angular/tree/master/packages/zone.js/
MIT License
3.25k stars 408 forks source link

build: make legacy standalone bundle #1201

Closed JiaLiPassion closed 5 years ago

JiaLiPassion commented 5 years ago

In angular cli, there is a file named es2015-polyfill.js, inside this file, all polyfill for es5 legacy browsers will be there, so with zone evergreen bundle, the most idle way to handle this is.

  1. put a zone-legacy.js inside es2015-polyfill.js.
  2. put zone-evergreen.js inside polyfill.ts.

So

  1. in es5 legacy browser, it will load zone-legacy.js + zone-evergreen.js.
  2. in modern browser, it will only load zone-evergreen.js.

Before this PR, zone-legacy.js need to be loaded after zone-evergreen.js, because the zone-legacy use a lot of common logic from zone-evergreen.js. So in this PR,

  1. zone-legacy.js is a lazy load module which will only define a factory function.
  2. When zone-evergreen.js loading, it will check whether this lazy load module exist, if exists, it will execute the zone-legacy patch logic.