| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class FlagAllModulesAsUsedPlugin { | 
					
						
							|  |  |  | 	constructor(explanation) { | 
					
						
							|  |  |  | 		this.explanation = explanation; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							|  |  |  | 			"FlagAllModulesAsUsedPlugin", | 
					
						
							|  |  |  | 			compilation => { | 
					
						
							|  |  |  | 				const moduleGraph = compilation.moduleGraph; | 
					
						
							|  |  |  | 				compilation.hooks.optimizeDependencies.tap( | 
					
						
							|  |  |  | 					"FlagAllModulesAsUsedPlugin", | 
					
						
							|  |  |  | 					modules => { | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | 						/** @type {RuntimeSpec} */ | 
					
						
							|  |  |  | 						let runtime = undefined; | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 						for (const [name, { options }] of compilation.entries) { | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | 							runtime = mergeRuntimeOwned( | 
					
						
							|  |  |  | 								runtime, | 
					
						
							|  |  |  | 								getEntryRuntime(compilation, name, options) | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 						for (const module of modules) { | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 							const exportsInfo = moduleGraph.getExportsInfo(module); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | 							exportsInfo.setUsedInUnknownWay(runtime); | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 							moduleGraph.addExtraReason(module, this.explanation); | 
					
						
							| 
									
										
										
										
											2020-12-15 23:38:20 +08:00
										 |  |  | 							if (module.factoryMeta === undefined) { | 
					
						
							|  |  |  | 								module.factoryMeta = {}; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							module.factoryMeta.sideEffectFree = false; | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = FlagAllModulesAsUsedPlugin; |