mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
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
This commit is contained in:

committed by
Dan Bucholtz

parent
11f4f516fc
commit
bcec66c67b
@ -41,4 +41,3 @@ export const NPM_VENDOR_FILES = [
|
||||
|
||||
// SERVER
|
||||
export const LOCAL_SERVER_PORT = 8080;
|
||||
|
||||
|
@ -9,4 +9,5 @@ import './tasks/release';
|
||||
import './tasks/snapshot';
|
||||
import './tasks/test';
|
||||
import './tasks/polyfill';
|
||||
import './tasks/polyfill.source';
|
||||
//import './tasks/theme';
|
||||
|
@ -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');
|
||||
|
7
scripts/gulp/tasks/polyfill.source.ts
Normal file
7
scripts/gulp/tasks/polyfill.source.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { task } from 'gulp';
|
||||
import { writePolyfills } from '../util';
|
||||
|
||||
|
||||
task('src.polyfill', () => {
|
||||
writePolyfills('scripts/polyfill');
|
||||
});
|
@ -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.write', () => {
|
||||
writePolyfills('dist/ionic-angular/polyfills');
|
||||
});
|
||||
|
||||
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.copy-readme', (done) => {
|
||||
task('polyfill.copy-readme', (done: Function) => {
|
||||
return src('scripts/polyfill/readme.md')
|
||||
.pipe(dest('dist/ionic-angular/polyfills/'), done);
|
||||
});
|
||||
|
@ -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');
|
||||
});
|
||||
|
@ -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}`
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user