UNPKG

898 BJavaScriptView Raw
1var md5 = require("md5");
2
3function compareModules(a,b) {
4 if (a.resource < b.resource)
5 return -1;
6 if (a.resource > b.resource)
7 return 1;
8 return 0;
9}
10
11function getModuleSource (module) {
12 var _source = module._source || {};
13 return _source._value || "";
14}
15
16function concatenateSource (result, module_source) {
17 return result + module_source;
18}
19
20function WebpackMd5Hash () {
21
22}
23
24WebpackMd5Hash.prototype.apply = function(compiler) {
25 compiler.plugin("compilation", function(compilation) {
26 compilation.plugin("chunk-hash", function(chunk, chunkHash) {
27 var source = chunk.modules.sort(compareModules).map(getModuleSource).reduce(concatenateSource);
28 var chunk_hash = md5(source);
29 chunkHash.digest = function () {
30 return chunk_hash;
31 };
32 });
33 });
34};
35
36module.exports = WebpackMd5Hash;
\No newline at end of file