gulp-browser/dist/gulpbrowser.browserify.js

43 lines
3.6 KiB
JavaScript
Raw Normal View History

"use strict";
2016-07-26 16:15:03 +00:00
const plugins = require("./gulpbrowser.plugins");
let browserify = function (transforms = []) {
2016-05-13 18:04:41 +00:00
if (!Array.isArray(transforms)) {
transforms = [transforms];
}
2016-07-26 16:15:03 +00:00
let forEach = function (file, enc, cb) {
let bundleCallback = function (err, bufferedContent) {
2016-02-26 16:57:53 +00:00
if (Buffer.isBuffer(bufferedContent)) {
file.contents = bufferedContent;
}
else {
2016-12-13 22:01:25 +00:00
console.log('gulp-browser: .browserify() ' + err.message);
cb(new Error(err.message), file);
return;
2016-02-26 16:57:53 +00:00
}
cb(null, file);
};
if (file.contents.length > 0) {
2016-07-26 16:15:03 +00:00
let browserified = plugins.browserify(file, { basedir: file.base });
2016-05-13 18:04:41 +00:00
transforms.forEach(function (transform) {
if (typeof transform === 'function') {
2016-07-26 16:15:03 +00:00
browserified.transform(transform);
2016-05-13 18:04:41 +00:00
}
else {
2016-07-26 16:15:03 +00:00
browserified.transform(transform.transform, transform.options);
2016-05-13 18:04:41 +00:00
}
});
2016-07-26 16:15:03 +00:00
browserified.bundle(bundleCallback);
}
else {
2016-12-13 22:01:25 +00:00
console.warn('gulp-browser: .browserify() file.contents appears to be empty');
cb(null, file);
}
;
};
2016-07-26 16:15:03 +00:00
let atEnd = function (cb) {
cb();
}; // no need to clean up after ourselves
2016-07-26 16:15:03 +00:00
return plugins.through2.obj(forEach, atEnd); // this is the through object that gets returned by gulpBrowser.browserify();
2016-02-26 16:57:53 +00:00
};
module.exports = browserify;
2016-12-13 22:01:25 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3VscGJyb3dzZXIuYnJvd3NlcmlmeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2d1bHBicm93c2VyLmJyb3dzZXJpZnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW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