From c0b04ca0bc762bc925434a8762eee74ce999e57e Mon Sep 17 00:00:00 2001 From: Rob Wormald Date: Mon, 23 Mar 2015 13:18:05 -0700 Subject: [PATCH] feat(gulp): adds System.register bundle task. --- .gitignore | 3 ++ gulpfile.js | 70 ++++++++++++++++++++++++++++++++++++++++++- package.json | 2 ++ tools/build/bundle.js | 7 +++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tools/build/bundle.js diff --git a/.gitignore b/.gitignore index f1a5dab0c2..16a2b265a8 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ pubspec.lock # Don't check in secret files *secret.js +# Ignore npm debug log +npm-debug.log + /docs/bower_components/ diff --git a/gulpfile.js b/gulpfile.js index 571c27761a..05a1794bff 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -29,9 +29,13 @@ var transformCJSTests = require('./tools/build/transformCJSTests'); var tsc = require('gulp-typescript'); var ts2dart = require('gulp-ts2dart'); var util = require('./tools/build/util'); +var bundler = require('./tools/build/bundle'); +var concat = require('gulp-concat'); // Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped. + var DART_SDK = require('./tools/build/dartdetect')(gulp); + // ----------------------- // configuration @@ -787,7 +791,71 @@ gulp.task('build.js.cjs', function(done) { ); }); -gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs']); +var bundleConfig = { + paths: { + "*": "dist/js/prod/es6/*.es6", + "rx/*": "node_modules/rx/*.js" + } +}; + +// production build +gulp.task('bundle.js.prod', ['build.js.prod'], function() { + return bundler.bundle( + bundleConfig, + 'angular2/angular2', + './dist/build/angular2.js', + { + sourceMaps: true + }); +}); + +gulp.task('bundle.js.prod.deps', ['bundle.js.prod'], function() { + return gulp.src(['node_modules/zone.js/zone.js', 'dist/build/angular2.js']) + .pipe(concat('angular2.js')) + .pipe(gulp.dest('dist/bundle')); +}); + +// minified production build +// TODO: minify zone.js? +gulp.task('bundle.js.min', ['build.js.prod'], function() { + return bundler.bundle( + bundleConfig, + 'angular2/angular2', + './dist/build/angular2.min.js', + { + sourceMaps: true, + minify: true + }); +}); + +gulp.task('bundle.js.min.deps', ['bundle.js.min'], function() { + return gulp.src(['node_modules/zone.js/zone.js', 'dist/build/angular2.min.js']) + .pipe(concat('angular2.min.js')) + .pipe(gulp.dest('dist/bundle')); +}); + +// development build +gulp.task('bundle.js.dev', ['build.js.dev'], function() { + return bundler.bundle( + merge(true, bundleConfig, { + "*": "dist/js/dev/es6/*.es6" + }), + 'angular2/angular2', + './dist/build/angular2.dev.js', + { + sourceMaps: true + }); +}); + +gulp.task('bundle.js.dev.deps', ['bundle.js.dev'], function() { + return gulp.src(['node_modules/zone.js/zone.js', 'dist/build/angular2.dev.js']) + .pipe(concat('angular2.dev.js')) + .pipe(gulp.dest('dist/bundle')); +}); + +gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs', 'bundle.js.deps']); + +gulp.task('bundle.js.deps', ['bundle.js.prod.deps', 'bundle.js.dev.deps', 'bundle.js.min.deps']); gulp.task('clean', ['build/clean.js', 'build/clean.dart', 'build/clean.docs']); diff --git a/package.json b/package.json index a2d36ce8ba..c721ea8236 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "glob": "^4.0.6", "gulp": "^3.8.8", "gulp-changed": "^1.0.0", + "gulp-concat": "^2.5.2", "gulp-connect": "~1.0.5", "gulp-jasmine": "^1.0.1", "gulp-load-plugins": "^0.7.1", @@ -76,6 +77,7 @@ "run-sequence": "^0.3.6", "source-map": "^0.3.0", "sprintf-js": "1.0.*", + "systemjs-builder": "^0.10.3", "temp": "^0.8.1", "ternary-stream": "^1.2.3", "through2": "^0.6.1", diff --git a/tools/build/bundle.js b/tools/build/bundle.js new file mode 100644 index 0000000000..5616efca67 --- /dev/null +++ b/tools/build/bundle.js @@ -0,0 +1,7 @@ +module.exports.bundle = function(buildConfig, moduleName, outputFile, outputConfig){ + // loading it earlier interfers with custom traceur. + var Builder = require('systemjs-builder'); + var builder = new Builder(); + builder.config(buildConfig); + return builder.build(moduleName, outputFile, outputConfig); +}