mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
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:
81
gulpfile.js
81
gulpfile.js
@ -30,6 +30,7 @@ function getBabelOptions(moduleName, moduleType) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function buildDemoBundle(opts, done) {
|
function buildDemoBundle(opts, done) {
|
||||||
var glob = require('glob');
|
var glob = require('glob');
|
||||||
var webpack = require('webpack');
|
var webpack = require('webpack');
|
||||||
@ -77,6 +78,7 @@ function buildDemoBundle(opts, done) {
|
|||||||
var tscOptions = require('./tsconfig.json').compilerOptions;
|
var tscOptions = require('./tsconfig.json').compilerOptions;
|
||||||
var tscReporter = {
|
var tscReporter = {
|
||||||
error: function (error) {
|
error: function (error) {
|
||||||
|
// TODO
|
||||||
// suppress type errors until we convert everything to TS
|
// suppress type errors until we convert everything to TS
|
||||||
// console.error(error.message);
|
// console.error(error.message);
|
||||||
}
|
}
|
||||||
@ -177,7 +179,7 @@ gulp.task('clean', function(done) {
|
|||||||
del(['dist/**', '!dist'], done);
|
del(['dist/**', '!dist'], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
function transpile(moduleType) {
|
gulp.task('transpile', function(){
|
||||||
var merge = require('merge2');
|
var merge = require('merge2');
|
||||||
|
|
||||||
var tsResult = gulp.src([
|
var tsResult = gulp.src([
|
||||||
@ -185,18 +187,8 @@ function transpile(moduleType) {
|
|||||||
'!ionic/components/*/test/**/*',
|
'!ionic/components/*/test/**/*',
|
||||||
'!ionic/util/test/*'
|
'!ionic/util/test/*'
|
||||||
])
|
])
|
||||||
.pipe(cache('transpile', { optimizeMemory: true }))
|
.pipe(cache('transpile', { optimizeMemory: true }))
|
||||||
.pipe(tsc(tscOptions, undefined, tscReporter))
|
.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'))
|
|
||||||
|
|
||||||
// merge definition and source streams
|
// merge definition and source streams
|
||||||
return merge([
|
return merge([
|
||||||
@ -204,36 +196,43 @@ function transpile(moduleType) {
|
|||||||
tsResult.js
|
tsResult.js
|
||||||
])
|
])
|
||||||
.pipe(gulp.dest('dist'));
|
.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() {
|
gulp.task('bundle', ['transpile', 'copy.web-animations'], function(done){
|
||||||
var insert = require('gulp-insert');
|
//TODO
|
||||||
var concat = require('gulp-concat');
|
// 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
|
bundle(ionicConfig, finished);
|
||||||
if (flags.animations == 'polyfill') {
|
bundle(bundleConfig, finished);
|
||||||
prepend.push('window.Element.prototype.animate=undefined;');
|
|
||||||
|
function finished(){
|
||||||
|
numTasks--;
|
||||||
|
if (numTasks == 0) done();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return gulp.src([
|
function bundle(config, cb){
|
||||||
'node_modules/es6-shim/es6-shim.min.js',
|
var webpack = require('webpack');
|
||||||
'dist/src/es5/system/ionic/**/*.js'
|
var path = require('path');
|
||||||
])
|
|
||||||
.pipe(concat('ionic.js'))
|
webpack(config, function(err, stats){
|
||||||
.pipe(insert.prepend(prepend.join('\n')))
|
var statsOptions = {
|
||||||
.pipe(gulp.dest('dist/js/'));
|
'colors': true,
|
||||||
//TODO minify + sourcemaps
|
'modules': false,
|
||||||
});
|
'chunks': false,
|
||||||
|
'exclude': ['node_module'],
|
||||||
|
'errorDetails': true
|
||||||
|
}
|
||||||
|
console.log(stats.toString(statsOptions));
|
||||||
|
cb();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
gulp.task('temp.hack', function(){
|
gulp.task('temp.hack', function(){
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@ -262,14 +261,6 @@ gulp.task('temp.hack', function(){
|
|||||||
fs.writeFileSync(file, myHackedFileThatYouLove, 'utf8');
|
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() {
|
gulp.task('tests', function() {
|
||||||
return gulp.src('ionic/**/test/**/*.spec.ts')
|
return gulp.src('ionic/**/test/**/*.spec.ts')
|
||||||
.pipe(tsc(tscOptions, undefined, tscReporter))
|
.pipe(tsc(tscOptions, undefined, tscReporter))
|
||||||
|
19
scripts/npm/bundle.webpack.config.js
Normal file
19
scripts/npm/bundle.webpack.config.js
Normal 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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
16
scripts/npm/ionic.webpack.config.js
Normal file
16
scripts/npm/ionic.webpack.config.js
Normal 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'
|
||||||
|
]
|
||||||
|
};
|
Reference in New Issue
Block a user