mirror of https://github.com/webpack/webpack.git
skip commonModules if minChunks===Infinity
This commit is contained in:
parent
ee3a0bc41d
commit
6cbd6997d3
|
|
@ -68,8 +68,6 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
|
|||
throw new Error("Invalid chunkNames argument");
|
||||
}
|
||||
commonChunks.forEach(function processCommonChunk(commonChunk, idx) {
|
||||
var commonModulesCount = [];
|
||||
var commonModules = [];
|
||||
var usedChunks;
|
||||
if(Array.isArray(selectedChunks)) {
|
||||
usedChunks = chunks.filter(function(chunk) {
|
||||
|
|
@ -100,29 +98,33 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
|
|||
commonChunk.addChunk(asyncChunk);
|
||||
commonChunk = asyncChunk;
|
||||
}
|
||||
usedChunks.forEach(function(chunk) {
|
||||
chunk.modules.forEach(function(module) {
|
||||
var idx = commonModules.indexOf(module);
|
||||
if(idx < 0) {
|
||||
commonModules.push(module);
|
||||
commonModulesCount.push(1);
|
||||
} else {
|
||||
commonModulesCount[idx]++;
|
||||
}
|
||||
});
|
||||
});
|
||||
var reallyUsedChunks = [];
|
||||
var reallyUsedModules = [];
|
||||
commonModulesCount.forEach(function(count, idx) {
|
||||
var module = commonModules[idx];
|
||||
if(typeof minChunks === "function") {
|
||||
if(!minChunks(module, count))
|
||||
if (minChunks !== Infinity) {
|
||||
var commonModulesCount = [];
|
||||
var commonModules = [];
|
||||
usedChunks.forEach(function(chunk) {
|
||||
chunk.modules.forEach(function(module) {
|
||||
var idx = commonModules.indexOf(module);
|
||||
if(idx < 0) {
|
||||
commonModules.push(module);
|
||||
commonModulesCount.push(1);
|
||||
} else {
|
||||
commonModulesCount[idx]++;
|
||||
}
|
||||
});
|
||||
});
|
||||
var _minChunks = (minChunks || Math.max(2, usedChunks.length))
|
||||
commonModulesCount.forEach(function(count, idx) {
|
||||
var module = commonModules[idx];
|
||||
if(typeof minChunks === "function") {
|
||||
if(!minChunks(module, count))
|
||||
return;
|
||||
} else if(count < _minChunks) {
|
||||
return;
|
||||
} else if(count < (minChunks || Math.max(2, usedChunks.length))) {
|
||||
return;
|
||||
}
|
||||
reallyUsedModules.push(module);
|
||||
});
|
||||
}
|
||||
reallyUsedModules.push(module);
|
||||
});
|
||||
}
|
||||
if(minSize) {
|
||||
var size = reallyUsedModules.reduce(function(a, b) {
|
||||
return a + b.size();
|
||||
|
|
@ -130,6 +132,7 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
|
|||
if(size < minSize)
|
||||
return;
|
||||
}
|
||||
var reallyUsedChunks = [];
|
||||
reallyUsedModules.forEach(function(module) {
|
||||
usedChunks.forEach(function(chunk) {
|
||||
if(module.removeChunk(chunk)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue