Skip to content

Instantly share code, notes, and snippets.

@halfninja
Created March 29, 2017 15:01
Show Gist options
  • Save halfninja/4dd41e8160078b7e0c3b3d410a2189e0 to your computer and use it in GitHub Desktop.
Save halfninja/4dd41e8160078b7e0c3b3d410a2189e0 to your computer and use it in GitHub Desktop.
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