Last active
August 29, 2015 14:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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