Skip to content

Commit 323e386

Browse files
committed
document and test chunk merging
1 parent 0460211 commit 323e386

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,16 @@ You can also save this options object in a JSON file and use it with the shell c
522522
// normal loaders. This cannot be overridden in the require call.
523523
// You must pass a string instead of a RegExp if you use workers
524524

525+
maxChunks: 5, // (experimental)
526+
// default: undefined
527+
// limit the maximum number of chunks.
528+
// chunks are merged until the required number is reached
529+
530+
mergeSizeRatio: 2, // (experimental)
531+
// default: 0.2
532+
// when choosing the merged chunks the maximum of this formular is searched:
533+
// sizeSaveByChunkMerging - mergedChunkSize * mergeSizeRatio
534+
525535
workers: true,
526536
// default: false
527537
// options: true, false, number > 0, object of type webpack/lib/Workers

lib/buildDeps.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = function buildDeps(context, mainModule, options, callback) {
7878

7979
if(options.maxChunks) {
8080
while(depTree.chunkCount > options.maxChunks) {
81-
if(!removeOneChunk(depTree, true))
81+
if(!removeOneChunk(depTree, options, true))
8282
break;
8383
}
8484
}
@@ -747,7 +747,7 @@ function moduleSize(depTree, moduleId) {
747747
return depTree.modulesById[moduleId].source && depTree.modulesById[moduleId].source.length || 0;
748748
}
749749

750-
function removeOneChunk(depTree, force) {
750+
function removeOneChunk(depTree, options, force) {
751751
var chunks = [];
752752
for(var chunkId in depTree.chunks) {
753753
var chunk = depTree.chunks[chunkId];
@@ -775,7 +775,7 @@ function removeOneChunk(depTree, force) {
775775
sizeMerged += size + 10;
776776
}
777777
}
778-
var value = sizeSum * 2 - sizeMerged;
778+
var value = sizeSum - sizeMerged * (options.mergeSizeRatio === undefined ? 1.2 : options.mergeSizeRatio + 1);
779779
if(best == null || best[0] < value)
780780
best = [value, chunkA.id, chunkB.id];
781781
});

test/browsertest/libary2config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ module.exports = {
1010
}
1111
]
1212
}
13-
}
13+
},
14+
maxChunks: 2
1415
}

test/browsertest/node_modules/libary2/lib/main.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/browsertest/node_modules/libary2/lib/test.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)