mirror of https://github.com/webpack/webpack.git
				
				
				
			
		
			
				
	
	
		
			36 lines
		
	
	
		
			1001 B
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1001 B
		
	
	
	
		
			JavaScript
		
	
	
	
| /*
 | |
| 	MIT License http://www.opensource.org/licenses/mit-license.php
 | |
| 	Author Tobias Koppers @sokra
 | |
| */
 | |
| "use strict";
 | |
| 
 | |
| class FlagIncludedChunksPlugin {
 | |
| 
 | |
| 	apply(compiler) {
 | |
| 		compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", (compilation) => {
 | |
| 			compilation.hooks.optimizeChunkIds.tap("FlagIncludedChunksPlugin", (chunks) => {
 | |
| 				chunks.forEach((chunkA) => {
 | |
| 					chunks.forEach((chunkB) => {
 | |
| 						// as we iterate the same iterables twice
 | |
| 						// skip if we find ourselves
 | |
| 						if(chunkA === chunkB) return;
 | |
| 
 | |
| 						// instead of swapping A and B just bail
 | |
| 						// as we loop twice the current A will be B and B then A
 | |
| 						if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) return;
 | |
| 
 | |
| 						if(chunkB.getNumberOfModules() === 0) return;
 | |
| 
 | |
| 						// is chunkB in chunkA?
 | |
| 						for(const m of chunkB.modulesIterable) {
 | |
| 							if(!chunkA.containsModule(m)) return;
 | |
| 						}
 | |
| 						chunkA.ids.push(chunkB.id);
 | |
| 					});
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 	}
 | |
| }
 | |
| module.exports = FlagIncludedChunksPlugin;
 |