Skip to content

Instantly share code, notes, and snippets.

@thlorenz
Created August 20, 2013 21:17
Show Gist options
  • Save thlorenz/6287447 to your computer and use it in GitHub Desktop.
Save thlorenz/6287447 to your computer and use it in GitHub Desktop.
ideas to dedupe browserified files before they reach the bundle
// dedupe
var seenSources = {};
var crypto = require('crypto');
var through = require('through');
function getHash(data) {
return crypto
.createHash('md5')
.update(data)
.digest('hex');
}
function dedupe (file) {
console.log(file);
var src = '';
return through(write, end);
function write (buf) { src += buf; }
function end () {
var hash = getHash(src);
var seen = seenSources[hash];
/*if (seen) console.log('seen %s as\n %s', file, seen);
else seenSources[hash] = file;*/
if (file === '/Users/thlorenz/dev/js/projects/see-eat-sleep/ses-core/config/expose-jquery.js')
console.log(src);
this.queue(src);
this.queue(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment