Skip to content

Commit c5b52b5

Browse files
committed
keep chunk ids
1 parent cc4f834 commit c5b52b5

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

lib/Compilation.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,44 @@ Compilation.prototype.applyModuleIds = function applyModuleIds() {
383383
};
384384

385385
Compilation.prototype.applyChunkIds = function applyChunkIds() {
386-
var i = 0;
386+
var i = this.cache && this.cache["nextChunkId"] || 1;
387+
var usedIds = {0:true};
388+
if(this.cache) {
389+
if(!this.cache.chunks)
390+
this.cache.chunks = {};
391+
var keys = Object.keys(this.cache.chunks).slice();
392+
var cacheChunks = this.cache.chunks;
393+
this.cache.chunks = {};
394+
}
387395
this.chunks.forEach(function(chunk) {
388-
if(chunk.id === null)
389-
chunk.id = ++i;
396+
if(chunk.id === null) {
397+
if(this.cache) {
398+
for(var j = 0; j < keys.length; j++) {
399+
var chunkId = keys[j];
400+
var cacheChunk = cacheChunks[chunkId];
401+
if(usedIds[cacheChunk.id]) continue;
402+
if(chunk.blocks.some(function(block) {
403+
return cacheChunk.blocks.indexOf(block) >= 0;
404+
})) {
405+
usedIds[cacheChunk.id] = true;
406+
chunk.id = cacheChunk.id;
407+
break;
408+
}
409+
}
410+
}
411+
if(chunk.id === null)
412+
chunk.id = i++;
413+
if(this.cache) {
414+
this.cache.chunks["c"+chunk.id] = {
415+
id: chunk.id,
416+
blocks: chunk.blocks
417+
};
418+
}
419+
}
390420
if(!chunk.ids)
391421
chunk.ids = [chunk.id];
392-
});
422+
}, this);
423+
if(this.cache) this.cache["nextChunkId"] = i;
393424
};
394425

395426
Compilation.prototype.sortItems = function sortItems() {

0 commit comments

Comments
 (0)