Last active
January 11, 2017 04:16
-
-
Save wbyoung/fa0192055cbca40887b449b60536a868 to your computer and use it in GitHub Desktop.
Plugin to address browserify/browserify#1505
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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