| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 19:28:29 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 13:20:24 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | /** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "ContextExclusionPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 19:28:29 +08:00
										 |  |  | class ContextExclusionPlugin { | 
					
						
							| 
									
										
										
										
											2018-07-05 13:20:24 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RegExp} negativeMatcher Matcher regular expression | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-09-25 19:28:29 +08:00
										 |  |  | 	constructor(negativeMatcher) { | 
					
						
							|  |  |  | 		this.negativeMatcher = negativeMatcher; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 13:20:24 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2018-11-03 04:05:46 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2018-07-05 13:20:24 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-09-25 19:28:29 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, (cmf) => { | 
					
						
							|  |  |  | 			cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, (files) => | 
					
						
							|  |  |  | 				files.filter((filePath) => !this.negativeMatcher.test(filePath)) | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-09-25 19:28:29 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = ContextExclusionPlugin; |