Skip to content

Instantly share code, notes, and snippets.

@wbyoung
Last active January 11, 2017 04:16
Show Gist options
  • Save wbyoung/fa0192055cbca40887b449b60536a868 to your computer and use it in GitHub Desktop.
Save wbyoung/fa0192055cbca40887b449b60536a868 to your computer and use it in GitHub Desktop.
Plugin to address browserify/browserify#1505
var through = require('through2');
var setup = function(b, cb) {
b.on('reset', cb);
cb();
};
module.exports = function offsetify(b, externalBundles) {
setup(b, function() {
b.pipeline.get('sort').push(through.obj(function(row, enc, next) {
var offset = externalBundles.reduce(function(sum, eb) {
return sum + eb._offsetifyOffset;
}, 0);
row.index += offset;
for (var key in row.indexDeps) {
if ({}.hasOwnProperty.call(row.indexDeps, key)) {
row.indexDeps[key] += offset;
}
}
this.push(row);
next();
}));
});
externalBundles.forEach(function(eb) {
setup(eb, function() {
eb._offsetifyOffset = 0;
eb.pipeline.get('sort').push(through.obj(function(row, enc, next) {
eb._offsetifyOffset += 1;
this.push(row);
next();
}));
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment