Code coverage report for lib\optimize\LimitChunkCountPlugin.js

Statements: 36.11% (13 / 36)      Branches: 31.25% (5 / 16)      Functions: 50% (4 / 8)      Lines: 34.38% (11 / 32)      Ignored: none     

All files » lib\optimize\ » LimitChunkCountPlugin.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54        1 8   1   1 8 8 8 8 8 6 6                                                                          
/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
function LimitChunkCountPlugin(options) {
	this.options = options || {};
}
module.exports = LimitChunkCountPlugin;
 
LimitChunkCountPlugin.prototype.apply = function(compiler) {
	var options = this.options;
	compiler.plugin("compilation", function(compilation) {
		compilation.plugin("optimize-chunks", function(chunks) {
			var maxChunks = options.maxChunks;
			if(!maxChunks) return;
			Iif(maxChunks < 1) return;
			Eif(chunks.length <= maxChunks) return;
 
			if(chunks.length > maxChunks) {
				var combinations = [];
				chunks.forEach(function(a, idx) {
					for(var i = 0; i < idx; i++) {
						var b = chunks[i];
						combinations.push([b, a]);
					}
				});
 
				combinations.forEach(function(pair) {
					var a = pair[0].size(options);
					var b = pair[1].size(options);
					var ab = pair[0].integratedSize(pair[1], options);
					pair.unshift(a + b - ab, ab);
				});
				combinations = combinations.filter(function(pair) {
					return pair[1] !== false;
				});
				combinations.sort(function(a,b) {
					var diff = b[0] - a[0];
					if(diff !== 0) return diff;
					return a[1] - b[1];
				});
 
				var pair = combinations[0];
 
				if(pair && pair[2].integrate(pair[3], "limit")) {
					chunks.splice(chunks.indexOf(pair[3]), 1);
					this.restartApplyPlugins();
				}
			}
		});
	});
};