Created
March 29, 2017 15:01
-
-
Save halfninja/4dd41e8160078b7e0c3b3d410a2189e0 to your computer and use it in GitHub Desktop.
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
var crypto = require('crypto'); | |
var fs = require('fs'); | |
const PlayFingerprintsPlugin = function(options) { | |
this.apply = this.apply.bind(this, options || {}); | |
}; | |
PlayFingerprintsPlugin.prototype.apply = (options, compiler) => { | |
compiler.plugin('emit', (compilation, done) => { | |
for (const filename in compilation.assets) { | |
const hash = crypto.createHash("md5"); | |
hash.update(compilation.assets[filename].source()); | |
const md5 = hash.digest('hex'); | |
// Fingerprint .md5 file | |
compilation.assets[`${filename}.md5`] = { | |
source: () => md5, | |
size: () => md5.length, | |
}; | |
// Identical to original file but with hash prepended. | |
compilation.assets[`${md5}-${filename}`] = compilation.assets[filename]; | |
}; | |
done(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment