Skip to content

Commit 9fd1cdd

Browse files
committed
chore(build): update polyfills to optimize zone.js, include tslib for future app-scripts
1 parent 48b3243 commit 9fd1cdd

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@angular/platform-browser-dynamic": "4.1.3",
3737
"ionicons": "~3.0.0",
3838
"rxjs": "5.4.0",
39+
"tslib": "^1.7.1",
3940
"zone.js": "0.8.12"
4041
},
4142
"devDependencies": {

scripts/gulp/util.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ export function writePolyfills(outputDirectory: string) {
279279
'node_modules/core-js/es7/reflect.js',
280280
'node_modules/core-js/es6/reflect.js',
281281
'node_modules/zone.js/dist/zone.js',
282-
'scripts/polyfill/polyfill.dom.js'
282+
'scripts/polyfill/polyfill.dom.js',
283+
'node_modules/tslib/tslib.js'
283284
];
284285

285286
const ALL_ENTRIES = [
@@ -302,22 +303,54 @@ export function writePolyfills(outputDirectory: string) {
302303
'node_modules/core-js/es6/weak-set.js',
303304
'node_modules/core-js/es7/reflect.js',
304305
'node_modules/zone.js/dist/zone.js',
305-
'scripts/polyfill/polyfill.dom.js'
306+
'scripts/polyfill/polyfill.dom.js',
307+
'node_modules/tslib/tslib.js'
306308
];
307309

308310
const NG_ENTRIES = [
309311
'node_modules/core-js/es7/reflect.js',
310312
'node_modules/zone.js/dist/zone.js',
313+
'node_modules/tslib/tslib.js'
314+
];
315+
316+
const ZONE_ONLY = [
317+
'node_modules/zone.js/dist/zone.js',
311318
];
312319

313320
let promises = [];
314321
promises.push(bundlePolyfill(MODERN_ENTRIES, join(outputDirectory, 'polyfills.modern.js')));
315322
promises.push(bundlePolyfill(ALL_ENTRIES, join(outputDirectory, 'polyfills.js')));
316323
promises.push(bundlePolyfill(NG_ENTRIES, join(outputDirectory, 'polyfills.ng.js')));
317-
318-
return Promise.all(promises);
324+
promises.push(bundlePolyfill(ZONE_ONLY, join(outputDirectory, 'polyfills.zone.js')));
325+
326+
return Promise.all(promises).then(() => {
327+
const promises = [];
328+
promises.push(appendZoneUpdatesToPolyfill(join(outputDirectory, 'polyfills.modern.js')));
329+
promises.push(appendZoneUpdatesToPolyfill(join(outputDirectory, 'polyfills.js')));
330+
promises.push(appendZoneUpdatesToPolyfill(join(outputDirectory, 'polyfills.ng.js')));
331+
promises.push(appendZoneUpdatesToPolyfill(join(outputDirectory, 'polyfills.zone.js')));
332+
return Promise.all(promises);
333+
});
319334
};
320335

336+
function appendZoneUpdatesToPolyfill(filePath: string) {
337+
return readFileAsync(filePath).then((fileContent: string) => {
338+
const updated = disablePartsOfZone(fileContent);
339+
return writeFileAsync(filePath, updated);
340+
});
341+
}
342+
343+
function disablePartsOfZone(fileContent: string) {
344+
const zoneContent = `__Zone_disable_Error = true;
345+
__Zone_disable_on_property = true;
346+
__Zone_disable_geolocation = true;
347+
__Zone_disable_toString = true;
348+
__Zone_disable_blocking = true;
349+
__Zone_disable_PromiseRejectionEvent = true;`;
350+
return `${zoneContent}
351+
${fileContent}`;
352+
}
353+
321354
function bundlePolyfill(pathsToIncludeInPolyfill: string[], outputPath: string) {
322355
return rollup({
323356
entry: pathsToIncludeInPolyfill,

0 commit comments

Comments
 (0)