Created
August 20, 2013 21:17
-
-
Save thlorenz/6287447 to your computer and use it in GitHub Desktop.
ideas to dedupe browserified files before they reach the bundle
This file contains 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
// 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