gulp-browser/ts/gulpbrowser.browserify.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-02-26 16:57:53 +00:00
/// <reference path="./typings/main.d.ts" />
import plugins = require("./gulpbrowser.plugins");
2016-02-26 16:57:53 +00:00
let browserify = function() {
let forEach = function(file, enc, cb){ // do this with every chunk (file in gulp terms)
let bundleCallback = function(err, bufferedContent) { // our bundle callback for when browserify is finished
if (Buffer.isBuffer(bufferedContent)){
file.contents = bufferedContent;
} else {
plugins.beautylog.error("gulp-browser: .browserify() " + err.message);
cb(new Error(err.message),file);
return;
}
cb(null,file);
};
if(file.contents.length > 0){
2016-02-26 16:57:53 +00:00
plugins.browserify(file, { basedir: file.base })
.bundle(bundleCallback);
} else {
plugins.beautylog.warn("gulp-browser: .browserify() file.contents appears to be empty");
cb(null,file);
};
}
let atEnd = function(cb){
cb();
} // no need to clean up after ourselves
return plugins.through.obj(forEach,atEnd); // this is the through object that gets returned by gulpBrowser.browserify();
2016-02-26 16:57:53 +00:00
};
export = browserify;