Sha256: 72d205024a284dc4fd0ae1a2045e73101a87286f52e9840e6cd4123abe79592a

Contents?: true

Size: 1.46 KB

Versions: 62

Compression:

Stored size: 1.46 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
function hasModule(chunk, module, checkedChunks) {
	if(chunk.modules.indexOf(module) >= 0) return [chunk];
	if(chunk.entry) return false;
	return allHaveModule(chunk.parents.filter(function(c) {
		return checkedChunks.indexOf(c) < 0;
	}), module, checkedChunks);
}

function allHaveModule(someChunks, module, checkedChunks) {
	if(!checkedChunks) checkedChunks = [];
	var chunks = [];
	for(var i = 0; i < someChunks.length; i++) {
		checkedChunks.push(someChunks[i]);
		var subChunks = hasModule(someChunks[i], module, checkedChunks);
		if(!subChunks) return false;
		addToSet(chunks, subChunks);
	}
	return chunks;
}

function addToSet(set, items) {
	items.forEach(function(item) {
		if(set.indexOf(item) < 0)
			set.push(item);
	});
}

function RemoveParentModulesPlugin() {
}
module.exports = RemoveParentModulesPlugin;

RemoveParentModulesPlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation) {
		compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
			chunks.forEach(function(chunk) {
				chunk.modules.slice().forEach(function(module) {
					if(chunk.entry) return;
					var parentChunksWithModule = allHaveModule(chunk.parents, module);
					if(parentChunksWithModule) {
						module.rewriteChunkInReasons(chunk, parentChunksWithModule);
						chunk.removeModule(module);
					}
				});
			});
		});
	});
};

Version data entries

62 entries across 62 versions & 1 rubygems

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