Skip to content

Commit ea7fd67

Browse files
committed
fixed webpack#1239
1 parent bf3ea10 commit ea7fd67

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

lib/Chunk.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ Chunk.prototype.integratedSize = function(other, options) {
227227
return modulesSize * (this.initial || other.initial ? ENTRY_CHUNK_MULTIPLICATOR : 1) + CHUNK_OVERHEAD;
228228
};
229229

230-
Chunk.prototype.getChunkMaps = function(includeEntries) {
230+
Chunk.prototype.getChunkMaps = function(includeEntries, realHash) {
231231
var chunksProcessed = [];
232232
var chunkHashMap = {};
233233
var chunkNameMap = {};
234234
(function addChunk(c) {
235235
if(chunksProcessed.indexOf(c) >= 0) return;
236236
chunksProcessed.push(c);
237237
if(!c.entry || includeEntries) {
238-
chunkHashMap[c.id] = c.renderedHash;
238+
chunkHashMap[c.id] = realHash ? c.hash : c.renderedHash;
239239
if(c.name)
240240
chunkNameMap[c.id] = c.name;
241241
}

lib/Compilation.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,14 @@ Compilation.prototype.createHash = function createHash() {
770770
this.chunkTemplate.updateHash(hash);
771771
this.moduleTemplate.updateHash(hash);
772772
var i, chunk;
773-
for(i = 0; i < this.chunks.length; i++) {
774-
chunk = this.chunks[i];
773+
var chunks = this.chunks.slice();
774+
chunks.sort(function(a, b) {
775+
if(a.entry && !b.entry) return 1;
776+
if(!a.entry && b.entry) return -1;
777+
return 0;
778+
});
779+
for(i = 0; i < chunks.length; i++) {
780+
chunk = chunks[i];
775781
var chunkHash = require("crypto").createHash(hashFunction);
776782
chunk.updateHash(chunkHash);
777783
if(chunk.entry) {

lib/TemplatedPathPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ TemplatedPathPlugin.prototype.apply = function(compiler) {
8888
var outputOptions = this.outputOptions;
8989
var publicPath = outputOptions.publicPath || "";
9090
var filename = outputOptions.filename || "";
91-
var chunkFilename = outputOptions.chunkFilename || "";
91+
var chunkFilename = outputOptions.chunkFilename || outputOptions.filename;
9292
if(REGEXP_HASH_FOR_TEST.test(publicPath) || REGEXP_CHUNKHASH_FOR_TEST.test(publicPath) || REGEXP_NAME_FOR_TEST.test(publicPath))
9393
return true;
9494
if(REGEXP_HASH_FOR_TEST.test(filename))
@@ -101,11 +101,11 @@ TemplatedPathPlugin.prototype.apply = function(compiler) {
101101

102102
mainTemplate.plugin("hash-for-chunk", function(hash, chunk) {
103103
var outputOptions = this.outputOptions;
104-
var chunkFilename = outputOptions.chunkFilename || "";
104+
var chunkFilename = outputOptions.chunkFilename || outputOptions.filename;
105105
if(REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
106-
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
106+
hash.update(JSON.stringify(chunk.getChunkMaps(true, true).hash));
107107
if(REGEXP_NAME_FOR_TEST.test(chunkFilename))
108-
hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
108+
hash.update(JSON.stringify(chunk.getChunkMaps(true, true).name));
109109
});
110110
});
111111
};

test/statsCases/chunks/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hash: 50078353b18e95d51f49
1+
Hash: 27b51279f30c19c26769
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
bundle.js 3.83 kB 0 [emitted] main

0 commit comments

Comments
 (0)