| 
									
										
										
										
											2024-05-01 22:22:45 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Authors Ivan Kopeykin @vankop | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "PlatformPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-01 22:22:45 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Should be used only for "target === false" or | 
					
						
							|  |  |  |  * when you want to overwrite platform target properties | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class PlatformPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Partial<PlatformTargetProperties>} platform target properties | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(platform) { | 
					
						
							|  |  |  | 		/** @type {Partial<PlatformTargetProperties>} */ | 
					
						
							|  |  |  | 		this.platform = platform; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 		compiler.hooks.environment.tap(PLUGIN_NAME, () => { | 
					
						
							| 
									
										
										
										
											2024-05-01 23:10:57 +08:00
										 |  |  | 			compiler.platform = { | 
					
						
							|  |  |  | 				...compiler.platform, | 
					
						
							| 
									
										
										
										
											2024-05-01 22:22:45 +08:00
										 |  |  | 				...this.platform | 
					
						
							| 
									
										
										
										
											2024-05-01 23:10:57 +08:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2024-05-01 22:22:45 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = PlatformPlugin; |