| 
									
										
										
										
											2013-02-24 09:05:55 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-05 06:23:48 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FlagIncludedChunksPlugin { | 
					
						
							| 
									
										
										
										
											2013-02-24 09:05:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 06:23:48 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.plugin("compilation", (compilation) => { | 
					
						
							|  |  |  | 			compilation.plugin("optimize-chunk-ids", (chunks) => { | 
					
						
							|  |  |  | 				chunks.forEach((chunkA) => { | 
					
						
							|  |  |  | 					chunks.forEach((chunkB) => { | 
					
						
							| 
									
										
										
										
											2017-02-23 20:39:19 +08:00
										 |  |  | 						// as we iterate the same iterables twice
 | 
					
						
							|  |  |  | 						// skip if we find ourselves
 | 
					
						
							| 
									
										
										
										
											2017-01-05 06:23:48 +08:00
										 |  |  | 						if(chunkA === chunkB) return; | 
					
						
							| 
									
										
										
										
											2017-02-23 20:39:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// instead of swapping A and B just bail
 | 
					
						
							|  |  |  | 						// as we loop twice the current A will be B and B then A
 | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 						if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) return; | 
					
						
							| 
									
										
										
										
											2017-02-23 20:39:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 						if(chunkB.getNumberOfModules() === 0) return; | 
					
						
							| 
									
										
										
										
											2017-03-18 09:20:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 20:39:19 +08:00
										 |  |  | 						// is chunkB in chunkA?
 | 
					
						
							| 
									
										
										
										
											2017-05-20 20:46:21 +08:00
										 |  |  | 						for(const m of chunkB.modulesIterable) { | 
					
						
							| 
									
										
										
										
											2017-04-21 16:05:56 +08:00
										 |  |  | 							if(!chunkA.containsModule(m)) return; | 
					
						
							| 
									
										
										
										
											2017-01-05 06:23:48 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 						chunkA.ids.push(chunkB.id); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2013-02-24 09:05:55 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-05 06:23:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = FlagIncludedChunksPlugin; |