gulp-browser/dist/gulpbrowser.browserify.js

43 lines
3.7 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 {
plugins.beautylog.error("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 {
plugins.beautylog.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-07-26 16:15:03 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3VscGJyb3dzZXIuYnJvd3NlcmlmeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2d1bHBicm93c2VyLmJyb3dzZXJpZnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQU8sT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