From bcec66c67bd256d1f247663b964514858415a170 Mon Sep 17 00:00:00 2001 From: Justin Willis Date: Tue, 20 Sep 2016 00:27:25 -0500 Subject: [PATCH] feat(polyfills): split up code and source polyfill task (#8130) * feat(polyfills): split up code and source polyfill task * fix(polyfills): get rid of need for entries argument --- scripts/gulp/constants.ts | 1 - scripts/gulp/gulpfile.ts | 1 + scripts/gulp/tasks/e2e.ts | 10 ++- scripts/gulp/tasks/polyfill.source.ts | 7 ++ scripts/gulp/tasks/polyfill.ts | 97 ++------------------------- scripts/gulp/tasks/release.ts | 8 ++- scripts/gulp/util.ts | 73 ++++++++++++++++++++ 7 files changed, 100 insertions(+), 97 deletions(-) create mode 100644 scripts/gulp/tasks/polyfill.source.ts diff --git a/scripts/gulp/constants.ts b/scripts/gulp/constants.ts index 3a09707550c..6775729cb21 100644 --- a/scripts/gulp/constants.ts +++ b/scripts/gulp/constants.ts @@ -41,4 +41,3 @@ export const NPM_VENDOR_FILES = [ // SERVER export const LOCAL_SERVER_PORT = 8080; - diff --git a/scripts/gulp/gulpfile.ts b/scripts/gulp/gulpfile.ts index 21aec8b5699..2bb4f9b921d 100644 --- a/scripts/gulp/gulpfile.ts +++ b/scripts/gulp/gulpfile.ts @@ -9,4 +9,5 @@ import './tasks/release'; import './tasks/snapshot'; import './tasks/test'; import './tasks/polyfill'; +import './tasks/polyfill.source'; //import './tasks/theme'; diff --git a/scripts/gulp/tasks/e2e.ts b/scripts/gulp/tasks/e2e.ts index 7b25450f41e..86726a8f732 100644 --- a/scripts/gulp/tasks/e2e.ts +++ b/scripts/gulp/tasks/e2e.ts @@ -3,13 +3,14 @@ import {dest, src, start, task} from 'gulp'; import * as path from 'path'; import { accessSync, F_OK, readFileSync, writeFileSync } from 'fs'; -import { compileSass, copyFonts, createTempTsConfig, createTimestamp, deleteFiles, runNgc, runWebpack, setSassIonicVersion } from '../util'; +import { compileSass, copyFonts, createTempTsConfig, createTimestamp, deleteFiles, runNgc, runWebpack, setSassIonicVersion, writePolyfills } from '../util'; + task('e2e', e2eBuild); function e2eBuild(done: Function) { const runSequence = require('run-sequence'); - runSequence('polyfill', 'e2e.copySource', 'e2e.compileTests', 'e2e.copyExternalDependencies', 'e2e.sass', 'e2e.fonts', 'e2e.beforeWebpack', 'e2e.runWebpack', done); + runSequence('e2e.polyfill', 'e2e.copySource', 'e2e.compileTests', 'e2e.copyExternalDependencies', 'e2e.sass', 'e2e.fonts', 'e2e.beforeWebpack', 'e2e.runWebpack', done); } task('e2e.copyAndCompile', (done: Function) => { @@ -209,6 +210,11 @@ task('e2e.watch', ['e2e.copyExternalDependencies', 'e2e.sass', 'e2e.fonts'], (do } }); + +task('e2e.polyfill', () => { + writePolyfills('dist/e2e/polyfills'); +}); + function e2eWatch(componentName: string, componentTest: string) { const watch = require('gulp-watch'); const webpack = require('webpack'); diff --git a/scripts/gulp/tasks/polyfill.source.ts b/scripts/gulp/tasks/polyfill.source.ts new file mode 100644 index 00000000000..acb566445e9 --- /dev/null +++ b/scripts/gulp/tasks/polyfill.source.ts @@ -0,0 +1,7 @@ +import { task } from 'gulp'; +import { writePolyfills } from '../util'; + + +task('src.polyfill', () => { + writePolyfills('scripts/polyfill'); +}); diff --git a/scripts/gulp/tasks/polyfill.ts b/scripts/gulp/tasks/polyfill.ts index c314ffe7f66..b70b5789535 100644 --- a/scripts/gulp/tasks/polyfill.ts +++ b/scripts/gulp/tasks/polyfill.ts @@ -1,100 +1,13 @@ import { task, src, dest } from 'gulp'; -const rollup = require('rollup'); -const nodeResolve = require('rollup-plugin-node-resolve'); -const commonjs = require('rollup-plugin-commonjs'); -const multiEntry = require('rollup-plugin-multi-entry'); -const uglify = require('rollup-plugin-uglify'); +import { writePolyfills } from '../util'; -const nodeResolveOptions = { - jsnext: true, - main: true -}; +task('polyfill', ['polyfill.copy-readme', 'polyfill.write']); -const modernEntries = [ - 'node_modules/core-js/es6/array.js', - 'node_modules/core-js/es6/date.js', - 'node_modules/core-js/es6/function.js', - 'node_modules/core-js/es6/map.js', - 'node_modules/core-js/es6/number.js', - 'node_modules/core-js/es6/object.js', - 'node_modules/core-js/es6/parse-float.js', - 'node_modules/core-js/es6/parse-int.js', - 'node_modules/core-js/es6/promise.js', - 'node_modules/core-js/es6/set.js', - 'node_modules/core-js/es6/string.js', - 'node_modules/core-js/es7/reflect.js', - 'node_modules/core-js/es6/reflect.js', - 'node_modules/zone.js/dist/zone.js', -]; - -const allEntries = [ - 'node_modules/core-js/es6/index.js', - 'node_modules/core-js/es7/reflect.js', - 'node_modules/zone.js/dist/zone.js', -]; - -const ngEntries = [ - 'node_modules/core-js/es7/reflect.js', - 'node_modules/zone.js/dist/zone.js', -]; - -task('polyfill', ['polyfill.modern', 'polyfill.all', 'polyfill.ng', 'polyfill.copy-readme']); - -task('polyfill.all', () => { - return rollup.rollup({ - entry: allEntries, - plugins: [ - multiEntry(), - nodeResolve(nodeResolveOptions), - commonjs(), - uglify() - ] - }).then((bundle) => { - bundle.write({ - format: 'iife', - moduleName: 'MyBundle', - dest: 'dist/ionic-angular/polyfills/polyfills.js' - }); - }); -}); - -task('polyfill.ng', () => { - return rollup.rollup({ - entry: ngEntries, - plugins: [ - multiEntry(), - nodeResolve(nodeResolveOptions), - commonjs(), - uglify() - ] - }).then((bundle) => { - bundle.write({ - format: 'iife', - moduleName: 'MyBundle', - dest: 'dist/ionic-angular/polyfills/polyfills.ng.js' - }); - }); -}); - -task('polyfill.modern', (done) => { - return rollup.rollup({ - entry: modernEntries, - plugins: [ - multiEntry(), - nodeResolve(nodeResolveOptions), - commonjs(), - uglify() - ] - }).then((bundle) => { - bundle.write({ - format: 'iife', - moduleName: 'MyBundle', - dest: 'dist/ionic-angular/polyfills/polyfills.modern.js' - }); - }); +task('polyfill.write', () => { + writePolyfills('dist/ionic-angular/polyfills'); }); -task('polyfill.copy-readme', (done) => { +task('polyfill.copy-readme', (done: Function) => { return src('scripts/polyfill/readme.md') .pipe(dest('dist/ionic-angular/polyfills/'), done); }); diff --git a/scripts/gulp/tasks/release.ts b/scripts/gulp/tasks/release.ts index 348bec33c79..55cfef6c3e6 100644 --- a/scripts/gulp/tasks/release.ts +++ b/scripts/gulp/tasks/release.ts @@ -1,6 +1,6 @@ import { dest, src, task } from 'gulp'; import { DIST_BUILD_ROOT, SRC_ROOT, PROJECT_ROOT } from '../constants'; -import { compileSass, copyFonts, setSassIonicVersion, createTimestamp } from '../util'; +import { compileSass, copyFonts, createTimestamp, setSassIonicVersion, writePolyfills } from '../util'; task('nightly', (done: Function) => { @@ -15,7 +15,7 @@ task('release.prepareNightly', (done: Function) => { task('release.nightlyPackage', (done: Function) => { const runSequence = require('run-sequence'); - runSequence('clean', /*'release.prepareNightly',*/ 'polyfill', 'compile.release', 'release.prepareNightly', 'release.compileSass', 'release.fonts', 'release.scss', done); + runSequence('clean', /*'release.prepareNightly',*/ 'release.polyfill', 'compile.release', 'release.prepareNightly', 'release.compileSass', 'release.fonts', 'release.scss', done); }); task('release.publishNightly', (done: Function) => { @@ -115,3 +115,7 @@ task('release.nightlyPackageJson', () => { fs.writeFileSync(`${DIST_BUILD_ROOT}/package.json`, JSON.stringify(packageJson, null, 2)); setSassIonicVersion(packageJson.version); }); + +task('release.polyfill', () => { + writePolyfills('dist/ionic-angular/polyfills'); +}); diff --git a/scripts/gulp/util.ts b/scripts/gulp/util.ts index 419fda88400..a6cc582e066 100644 --- a/scripts/gulp/util.ts +++ b/scripts/gulp/util.ts @@ -2,6 +2,11 @@ import { COMMONJS_MODULE, ES_MODULE, NODE_MODULES_ROOT, PROJECT_ROOT, SRC_ROOT, import { src, dest } from 'gulp'; import * as path from 'path'; import * as fs from 'fs'; +import { rollup } from 'rollup'; +const nodeResolve = require('rollup-plugin-node-resolve'); +const commonjs = require('rollup-plugin-commonjs'); +const multiEntry = require('rollup-plugin-multi-entry'); +const uglify = require('rollup-plugin-uglify'); export function mergeObjects(obj1: any, obj2: any ) { if (! obj1) { @@ -173,3 +178,71 @@ export function createTimestamp() { ('0' + (d.getUTCHours())).slice(-2) + // HH ('0' + (d.getUTCMinutes())).slice(-2); // MM } + +export function writePolyfills(pathToWrite: string) { + const MODERN_ENTRIES = [ + 'node_modules/core-js/es6/array.js', + 'node_modules/core-js/es6/date.js', + 'node_modules/core-js/es6/function.js', + 'node_modules/core-js/es6/map.js', + 'node_modules/core-js/es6/number.js', + 'node_modules/core-js/es6/object.js', + 'node_modules/core-js/es6/parse-float.js', + 'node_modules/core-js/es6/parse-int.js', + 'node_modules/core-js/es6/promise.js', + 'node_modules/core-js/es6/set.js', + 'node_modules/core-js/es6/string.js', + 'node_modules/core-js/es7/reflect.js', + 'node_modules/core-js/es6/reflect.js', + 'node_modules/zone.js/dist/zone.js', + ]; + + const ALL_ENTRIES = [ + 'node_modules/core-js/es6/index.js', + 'node_modules/core-js/es7/reflect.js', + 'node_modules/zone.js/dist/zone.js', + ]; + + const NG_ENTRIES = [ + 'node_modules/core-js/es7/reflect.js', + 'node_modules/zone.js/dist/zone.js', + ]; + + const ENTRIES = [ + { + entry: MODERN_ENTRIES, + fileName: 'polyfills.modern.js' + }, { + entry: ALL_ENTRIES, + fileName: 'polyfills.js' + }, { + entry: NG_ENTRIES, + fileName: 'polyfills.ng.js' + } + ]; + + for (let i = 0; i <= 3; i++) { + if (i === 3) { + return; + } else { + rollup({ + entry: ENTRIES[i].entry, + plugins: [ + multiEntry(), + nodeResolve({ + jsnext: true, + main: true + }), + commonjs(), + uglify() + ] + }).then((bundle) => { + bundle.write({ + format: 'iife', + moduleName: 'MyBundle', + dest: `${pathToWrite}/${ENTRIES[i].fileName}` + }); + }); + }; + }; +};