Skip to content

Commit

Permalink
feat(polyfills): split up code and source polyfill task (#8130)
Browse files Browse the repository at this point in the history
* feat(polyfills): split up code and source polyfill task

* fix(polyfills): get rid of need for entries argument
  • Loading branch information
jgw96 authored and danbucholtz committed Sep 20, 2016
1 parent 11f4f51 commit bcec66c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 97 deletions.
1 change: 0 additions & 1 deletion scripts/gulp/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ export const NPM_VENDOR_FILES = [

// SERVER
export const LOCAL_SERVER_PORT = 8080;

1 change: 1 addition & 0 deletions scripts/gulp/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ import './tasks/release';
import './tasks/snapshot';
import './tasks/test';
import './tasks/polyfill';
import './tasks/polyfill.source';
//import './tasks/theme';
10 changes: 8 additions & 2 deletions scripts/gulp/tasks/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
Expand Down
7 changes: 7 additions & 0 deletions scripts/gulp/tasks/polyfill.source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { task } from 'gulp';
import { writePolyfills } from '../util';


task('src.polyfill', () => {
writePolyfills('scripts/polyfill');
});
97 changes: 5 additions & 92 deletions scripts/gulp/tasks/polyfill.ts
Original file line number Diff line number Diff line change
@@ -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);
});
8 changes: 6 additions & 2 deletions scripts/gulp/tasks/release.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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');
});
73 changes: 73 additions & 0 deletions scripts/gulp/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`
});
});
};
};
};

0 comments on commit bcec66c

Please sign in to comment.