Skip to content

Instantly share code, notes, and snippets.

@jzelenkov
Created February 9, 2015 13:59
Show Gist options
  • Save jzelenkov/733f270de57d5186984a to your computer and use it in GitHub Desktop.
Save jzelenkov/733f270de57d5186984a to your computer and use it in GitHub Desktop.
updated minified.js for `minifyify` which mangles the whole output bundle js instead of each file individually
/*
* Consumes the output stream from Browserify
*/
Minifier.prototype.consumer = function (cb) {
var self = this;
return concat(function(data) {
if(!self.opts.minify) {
// Keep browserify's sourcemap
return cb(null, data.toString(), null);
}
else if (!self.opts.map) {
// Remove browserify's inline sourcemap
return cb(null, convertSM.removeComments(data.toString()), null);
}
else {
var bundle = self.decoupleBundle(data);
if(bundle === false) {
if(self.opts.minify)
throw new Error('Browserify must be in debug mode for minifyify to consume sourcemaps')
return cb(null, convertSM.removeComments(data.toString()));
}
// Re-maps the browserify sourcemap
// to the original source using the
// uglify sourcemap
bundle.map = self.transformMap(bundle.map);
var origSourceMap = JSON.parse(bundle.map);
var mangled = uglify.minify(bundle.code, {
sourceMapIncludeSources: true,
fromString: true,
inSourceMap: origSourceMap,
outSourceMap: self.opts.map // TODO: fix path to sourcemap file
});
bundle.code = mangled.code + '\n//# sourceMappingURL=' + self.opts.map
bundle.map = mangled.map
cb(null, bundle.code, bundle.map);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment