1 | var md5 = require("md5");
|
2 |
|
3 | function 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 |
|
11 | function getModuleSource (module) {
|
12 | var _source = module._source || {};
|
13 | return _source._value || "";
|
14 | }
|
15 |
|
16 | function concatenateSource (result, module_source) {
|
17 | return result + module_source;
|
18 | }
|
19 |
|
20 | function WebpackMd5Hash () {
|
21 |
|
22 | }
|
23 |
|
24 | WebpackMd5Hash.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 |
|
36 | module.exports = WebpackMd5Hash; |
\ | No newline at end of file |