bundling and minification - How can you bundle Angular 2 using System JS Builder? -
i'm using system js system js builder bundle application, assets, , libraries references. problem can bundle libraries referenced explicitly in index.html, e.g:
<script src="node_modules/es6-shim/es6-shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-metadata/reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script>
however, can't figure out how can bundle angular 2 itself, or @ least modules required angular 2, aren't referenced in html. how can done?
using systemjs-builder can bundle angular 2 app code , bundle other libraries separately.
i bundled library reference directly in html vendors.min.js, , library referenced through system.config.js plus app code app.min.js. in example can see dependencies in tour of heroes loaded page in <10 network requests (source code).
// bundle dependencies vendors file gulp.task('bundle:libs', function () { return gulp.src([ 'node_modules/jquery/dist/jquery.min.js', 'node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/semantic-ui/dist/semantic.min.js', 'node_modules/es6-shim/es6-shim.min.js', 'node_modules/es6-promise/dist/es6-promise.min.js', 'node_modules/systemjs/dist/system.src.js', 'system.config.js', ]) .pipe(concat('vendors.min.js')) .pipe(uglify()) .pipe(gulp.dest('public/lib/js')); }); // compile typescript js gulp.task('compile:ts', function () { return gulp .src([ "src/**/*.ts", "typings/*.d.ts" ]) .pipe(sourcemaps.init()) .pipe(tsc({ "module": "system", "moduleresolution": "node", "outdir": "public/dist/js", "target": "es5" })) .pipe(sourcemaps.write('.')) .pipe(gulp.dest('public/dist')); }); // generate systemjs-based builds gulp.task('bundle:js', function() { var builder = new sysbuilder('public', './system.config.js'); return builder.buildstatic('app', 'public/dist/js/app.min.js'); }); // minify js bundle gulp.task('minify:js', function() { return gulp .src('public/dist/js/app.min.js') .pipe(uglify()) .pipe(gulp.dest('public/dist/js')); }); gulp.task('scripts', ['compile:ts', 'bundle:js', 'minify:js']);
Comments
Post a Comment