Skip to content

Instantly share code, notes, and snippets.

@Twipped
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Twipped/23856fb12bdc794d3925 to your computer and use it in GitHub Desktop.
Save Twipped/23856fb12bdc794d3925 to your computer and use it in GitHub Desktop.
Gulpfile config to create a pipe that wraps the bootstrap js files with async module definitions, with jQuery AMD
var through2 = require('through2');
var path = require('path');
var gulp = require('gulp');
gulp.task('bootstrap', function () {
return gulp.src('./node_modules/bootstrap/js/*.js')
.pipe(through2.obj(function transform (file, enc, next) {
if (file.isNull()) {
this.push(file); // pass along
return next();
}
var basename = path.basename(file.path);
var src = file.contents.toString('utf8');
var compiled;
if (basename === 'transition.js') {
compiled = 'define([\'jquery/jquery\'], function (jQuery) {\n' + src + '\n\nreturn jQuery;\n});\n';
} else {
compiled = 'define([\'jquery/jquery\', \'bootstrap/transition\'], function (jQuery) {\n' + src + '\n\nreturn jQuery;\n});\n';
}
file.contents = new Buffer(compiled);
this.push(file);
next();
}))
.pipe(gulp.dest('./public/vendor/bootstrap-amd/'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment