Skip to content

Instantly share code, notes, and snippets.

@stewhouston
Created May 23, 2016 02:55
Show Gist options
  • Save stewhouston/27cac18c64d03b14de8b39389cbaa1c5 to your computer and use it in GitHub Desktop.
Save stewhouston/27cac18c64d03b14de8b39389cbaa1c5 to your computer and use it in GitHub Desktop.
Example of a bundling task for Angular 2 with gulp (so as to reduce http/xhr requests.) Works in the context of a project created through angular-cli.
gulp.task('ng-bundle', function(done) {
process.chdir('dist');
let bundleFilename = 'app.bundle.js';
const Builder = require('systemjs-builder');
let builder = new Builder();
builder.loadConfig('system-config.js')
.then(function() {
return builder
.buildStatic('main.js', bundleFilename, {
normalize: true,
minify: true,
mangle: true,
runtime: false
});
})
.then(function() {
console.log(`Bundle complete. \`stat ./dist/${bundleFilename}\``);
done();
})
.catch(function (err) {
console.log('error', err);
console.log('ng-bundle failed.');
process.exit(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment