| 
									
										
										
										
											2016-05-05 16:13:50 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | function EnsureChunkConditionsPlugin() {} | 
					
						
							|  |  |  | module.exports = EnsureChunkConditionsPlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EnsureChunkConditionsPlugin.prototype.apply = function(compiler) { | 
					
						
							|  |  |  | 	compiler.plugin("compilation", function(compilation) { | 
					
						
							|  |  |  | 		compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], function(chunks) { | 
					
						
							|  |  |  | 			var changed = false; | 
					
						
							|  |  |  | 			chunks.forEach(function(chunk) { | 
					
						
							|  |  |  | 				chunk.modules.slice().forEach(function(module) { | 
					
						
							|  |  |  | 					if(!module.chunkCondition) return; | 
					
						
							|  |  |  | 					if(!module.chunkCondition(chunk)) { | 
					
						
							| 
									
										
										
										
											2016-09-18 16:30:05 +08:00
										 |  |  | 						var usedChunks = module._EnsureChunkConditionsPlugin_usedChunks = (module._EnsureChunkConditionsPlugin_usedChunks || []).concat(chunk); | 
					
						
							|  |  |  | 						var newChunks = []; | 
					
						
							| 
									
										
										
										
											2016-05-05 16:13:50 +08:00
										 |  |  | 						chunk.parents.forEach(function(parent) { | 
					
						
							| 
									
										
										
										
											2016-09-18 16:30:05 +08:00
										 |  |  | 							if(usedChunks.indexOf(parent) < 0) { | 
					
						
							|  |  |  | 								parent.addModule(module); | 
					
						
							|  |  |  | 								newChunks.push(parent); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2016-05-05 16:13:50 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2016-09-18 16:30:05 +08:00
										 |  |  | 						module.rewriteChunkInReasons(chunk, newChunks); | 
					
						
							| 
									
										
										
										
											2016-05-05 16:13:50 +08:00
										 |  |  | 						chunk.removeModule(module); | 
					
						
							|  |  |  | 						changed = true; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			if(changed) return true; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; |