| 
									
										
										
										
											2016-08-17 18:05:29 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-12 00:08:13 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FlagInitialModulesAsUsedPlugin { | 
					
						
							| 
									
										
										
										
											2017-11-22 01:52:35 +08:00
										 |  |  | 	constructor(explanation) { | 
					
						
							|  |  |  | 		this.explanation = explanation; | 
					
						
							| 
									
										
										
										
											2017-11-20 22:41:30 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-12 00:08:13 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							|  |  |  | 			"FlagInitialModulesAsUsedPlugin", | 
					
						
							|  |  |  | 			compilation => { | 
					
						
							|  |  |  | 				compilation.hooks.afterOptimizeChunks.tap( | 
					
						
							|  |  |  | 					"FlagInitialModulesAsUsedPlugin", | 
					
						
							|  |  |  | 					chunks => { | 
					
						
							|  |  |  | 						for (const chunk of chunks) { | 
					
						
							|  |  |  | 							if (!chunk.isOnlyInitial()) { | 
					
						
							|  |  |  | 								return; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							for (const module of chunk.modulesIterable) { | 
					
						
							|  |  |  | 								module.used = true; | 
					
						
							|  |  |  | 								module.usedExports = true; | 
					
						
							|  |  |  | 								module.addReason(null, null, this.explanation); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-01-12 00:08:13 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-12 00:08:13 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = FlagInitialModulesAsUsedPlugin; |