bundle gulp task

Use webpack to create two UMD bundles - one of just ionic that
expects Angular2 to be an external module, the other that includes
zone.js, reflect-metadata, and angular2 as well.
This commit is contained in:
Tim Lancina
2015-12-04 15:06:48 -06:00
parent ffcdb2ebcd
commit 99cb565312
3 changed files with 71 additions and 45 deletions

View File

@ -30,6 +30,7 @@ function getBabelOptions(moduleName, moduleType) {
}
}
function buildDemoBundle(opts, done) {
var glob = require('glob');
var webpack = require('webpack');
@ -77,6 +78,7 @@ function buildDemoBundle(opts, done) {
var tscOptions = require('./tsconfig.json').compilerOptions;
var tscReporter = {
error: function (error) {
// TODO
// suppress type errors until we convert everything to TS
// console.error(error.message);
}
@ -177,7 +179,7 @@ gulp.task('clean', function(done) {
del(['dist/**', '!dist'], done);
});
function transpile(moduleType) {
gulp.task('transpile', function(){
var merge = require('merge2');
var tsResult = gulp.src([
@ -186,17 +188,7 @@ function transpile(moduleType) {
'!ionic/util/test/*'
])
.pipe(cache('transpile', { optimizeMemory: true }))
.pipe(tsc(tscOptions, undefined, tscReporter))
// .on('error', function(error) {
// tsResult.emit('end');
// })
// .pipe(gulp.dest('dist/src/es6/ionic'))
// .pipe(babel(getBabelOptions('ionic', moduleType)))
// .on('error', function (err) {
// console.log("ERROR: " + err.message);
// this.emit('end');
// })
// .pipe(gulp.dest('dist'))
.pipe(tsc(tscOptions, undefined, tscReporter));
// merge definition and source streams
return merge([
@ -204,36 +196,43 @@ function transpile(moduleType) {
tsResult.js
])
.pipe(gulp.dest('dist'));
}
gulp.task('transpile.system', function() { return transpile("system"); });
gulp.task('transpile.common', function() {
// necessary for publish task, remove if we ever do incremental builds with cjs
cache.caches && delete cache.caches.transpile;
return transpile("common");
});
gulp.task('transpile', ['transpile.common']);
gulp.task('bundle.ionic', ['transpile.system'], function() {
var insert = require('gulp-insert');
var concat = require('gulp-concat');
gulp.task('bundle', ['transpile', 'copy.web-animations'], function(done){
//TODO
// if (flags.animations == 'polyfill') {
// prepend.push('window.Element.prototype.animate=undefined;');
// }
var prepend = [];
var numTasks = 2;
var ionicConfig = require('./scripts/npm/ionic.webpack.config.js');
var bundleConfig = require('./scripts/npm/bundle.webpack.config.js');
// force the web animations api polyfill to kick in
if (flags.animations == 'polyfill') {
prepend.push('window.Element.prototype.animate=undefined;');
bundle(ionicConfig, finished);
bundle(bundleConfig, finished);
function finished(){
numTasks--;
if (numTasks == 0) done();
}
})
return gulp.src([
'node_modules/es6-shim/es6-shim.min.js',
'dist/src/es5/system/ionic/**/*.js'
])
.pipe(concat('ionic.js'))
.pipe(insert.prepend(prepend.join('\n')))
.pipe(gulp.dest('dist/js/'));
//TODO minify + sourcemaps
});
function bundle(config, cb){
var webpack = require('webpack');
var path = require('path');
webpack(config, function(err, stats){
var statsOptions = {
'colors': true,
'modules': false,
'chunks': false,
'exclude': ['node_module'],
'errorDetails': true
}
console.log(stats.toString(statsOptions));
cb();
})
}
gulp.task('temp.hack', function(){
var fs = require('fs');
@ -262,14 +261,6 @@ gulp.task('temp.hack', function(){
fs.writeFileSync(file, myHackedFileThatYouLove, 'utf8');
});
gulp.task('bundle', ['bundle.ionic'], function() {
var concat = require('gulp-concat');
return gulp.src(buildConfig.scripts)
.pipe(concat('ionic.bundle.js'))
.pipe(gulp.dest('dist/js'));
})
gulp.task('tests', function() {
return gulp.src('ionic/**/test/**/*.spec.ts')
.pipe(tsc(tscOptions, undefined, tscReporter))

View File

@ -0,0 +1,19 @@
module.exports = {
entry: [
"zone.js", // required for Angular change detection
"reflect-metadata", // required for Angular DI
"es6-shim/es6-shim.min.js",
"web-animations.min",
"./dist/ionic.js"
],
output: {
path: 'dist/bundles',
filename: 'ionic.bundle.js',
libraryTarget: 'umd'
},
resolve: {
alias: {
'web-animations.min': './dist/js/web-animations.min'
}
}
};

View File

@ -0,0 +1,16 @@
module.exports = {
entry: [
"es6-shim/es6-shim.min.js",
"./dist/ionic.js"
],
output: {
path: 'dist/bundles',
filename: 'ionic.js',
libraryTarget: 'umd'
},
externals: [
'angular2/angular2',
'angular2/router',
'angular2/http'
]
};