Sha256: 020e5c8501f5439f6daaa366390bedc452a63da42252ea37c7faca84ceb66768

Contents?: true

Size: 1.47 KB

Versions: 62

Compression:

Stored size: 1.47 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
function MinChunkSizePlugin(options) {
	this.options = options;
}
module.exports = MinChunkSizePlugin;

MinChunkSizePlugin.prototype.apply = function(compiler) {
	var options = this.options;
	var minChunkSize = options.minChunkSize;
	compiler.plugin("compilation", function(compilation) {
		compilation.plugin("optimize-chunks", function(chunks) {

			var combinations = [];
			chunks.forEach(function(a, idx) {
				for(var i = 0; i < idx; i++) {
					var b = chunks[i];
					combinations.push([b, a]);
				}
			});

			var equalOptions = {
				chunkOverhead: 1,
				entryChunkMultiplicator: 1
			};
			combinations = combinations.filter(function(pair) {
				return pair[0].size(equalOptions) < minChunkSize || pair[1].size(equalOptions) < minChunkSize;
			});

			if(combinations.length === 0) return;

			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];

			pair[2].integrate(pair[3], "min-size");
			chunks.splice(chunks.indexOf(pair[3]), 1);
			this.restartApplyPlugins();
		});
	});
};

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
smock-0.1.268 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.267 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.266 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.265 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.264 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.263 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.262 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.261 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.260 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.259 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.258 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.256 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.255 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.254 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.253 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.252 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.251 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.250 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.249 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js
smock-0.1.247 node_modules/webpack/lib/optimize/MinChunkSizePlugin.js