2016-04-01 13:56:35 +00:00
|
|
|
"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) {
|
2018-03-14 23:33:43 +00:00
|
|
|
// do this with every chunk (file in gulp terms)
|
2016-07-26 16:15:03 +00:00
|
|
|
let bundleCallback = function (err, bufferedContent) {
|
2018-03-14 23:33:43 +00:00
|
|
|
// our bundle callback for when browserify is finished
|
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);
|
2016-04-01 13:56:35 +00:00
|
|
|
cb(new Error(err.message), file);
|
|
|
|
return;
|
2016-02-26 16:57:53 +00:00
|
|
|
}
|
|
|
|
cb(null, file);
|
|
|
|
};
|
2016-04-01 13:56:35 +00:00
|
|
|
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);
|
2016-04-01 13:56:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-12-13 22:01:25 +00:00
|
|
|
console.warn('gulp-browser: .browserify() file.contents appears to be empty');
|
2016-04-01 13:56:35 +00:00
|
|
|
cb(null, file);
|
|
|
|
}
|
|
|
|
};
|
2016-07-26 16:15:03 +00:00
|
|
|
let atEnd = function (cb) {
|
2016-04-01 13:56:35 +00:00
|
|
|
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;
|
2018-03-14 23:33:43 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3VscGJyb3dzZXIuYnJvd3NlcmlmeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2d1bHBicm93c2VyLmJyb3dzZXJpZnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUNBLGlEQUFrRDtBQUdsRCxJQUFJLFVBQVUsR0FBRyxVQUFTLFVBQVUsR0FBRyxFQUFFO0lBQ3ZDLEVBQUUsQ0FBQyxDQUFDLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDL0IsVUFBVSxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUM7SUFDNUIsQ0FBQztJQUVELElBQUksT0FBTyxHQUFHLFVBQVMsSUFBSSxFQUFFLEdBQUcsRUFBRSxFQUFFO1FBQ2xDLGdEQUFnRDtRQUVoRCxJQUFJLGNBQWMsR0FBRyxVQUFTLEdBQUcsRUFBRSxlQUFlO1lBQ2hELHNEQUFzRDtZQUN0RCxFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLGVBQWUsQ0FBQyxDQUFDLENBQUMsQ0FBQztnQkFDckMsSUFBSSxDQUFDLFFBQVEsR0FBRyxlQUFlLENBQUM7WUFDbEM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