Skip to content

Commit ee58153

Browse files
committed
more reliable recording and hashing of async chunks
fixed webpack#433
1 parent 2c54cb1 commit ee58153

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

lib/AsyncDependenciesBlock.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ AsyncDependenciesBlock.prototype = Object.create(DependenciesBlock.prototype);
2727

2828
AsyncDependenciesBlock.prototype.updateHash = function updateHash(hash) {
2929
hash.update(this.chunkName || "");
30+
hash.update(this.chunks && this.chunks.map(function(chunk) {
31+
return typeof chunk.id === "number" ? chunk.id : "";
32+
}).join(",") || "");
3033
DependenciesBlock.prototype.updateHash.call(this, hash);
3134
};
3235

lib/RecordIdsPlugin.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
4242
});
4343
});
4444

45-
function getDepBlockIdent(block) {
45+
function getDepBlockIdent(chunk, block) {
4646
var ident = [];
47+
if(block.chunks.length > 1)
48+
ident.push(block.chunks.indexOf(chunk));
4749
while(block.parent) {
4850
var p = block.parent;
4951
var idx = p.blocks.indexOf(block);
@@ -62,7 +64,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
6264
if(!records.chunks.byBlocks) records.chunks.byBlocks = {};
6365
chunks.forEach(function(chunk) {
6466
var name = chunk.name;
65-
var blockIdents = chunk.blocks.map(getDepBlockIdent).filter(Boolean);
67+
var blockIdents = chunk.blocks.map(getDepBlockIdent.bind(null, chunk)).filter(Boolean);
6668
if(name) records.chunks.byName[name] = chunk.id;
6769
blockIdents.forEach(function(blockIdent) {
6870
records.chunks.byBlocks[blockIdent] = chunk.id;
@@ -91,16 +93,16 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
9193
}).map(function(chunk) {
9294
return {
9395
chunk: chunk,
94-
blockIdents: chunk.blocks.map(getDepBlockIdent).filter(Boolean)
96+
blockIdents: chunk.blocks.map(getDepBlockIdent.bind(null, chunk)).filter(Boolean)
9597
}
9698
}).filter(function(arg) {
9799
return arg.blockIdents.length > 0;
98100
});
99101
var blockIdentsCount = {};
100102
argumentedChunks.forEach(function(arg, idx) {
101103
arg.blockIdents.forEach(function(blockIdent) {
102-
var id = records.chunks.byBlocks[blockIdent]
103-
if(!id) return;
104+
var id = records.chunks.byBlocks[blockIdent];
105+
if(typeof id !== "number") return;
104106
var accessor = id + ":" + idx;
105107
blockIdentsCount[accessor] = (blockIdentsCount[accessor] || 0) + 1;
106108
});

0 commit comments

Comments
 (0)