| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | /** @typedef {import("../Compilation").EntryData} EntryData */ | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "RuntimeChunkPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | /** @typedef {(entrypoint: { name: string }) => string} RuntimeChunkFunction */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | class RuntimeChunkPlugin { | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 	 * @param {{ name?: RuntimeChunkFunction }=} options options | 
					
						
							| 
									
										
										
										
											2024-02-22 22:20:17 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-26 01:52:36 +08:00
										 |  |  | 	constructor(options) { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.options = { | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 			/** @type {RuntimeChunkFunction} */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			name: (entrypoint) => `runtime~${entrypoint.name}`, | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 			...options | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-01-26 01:52:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 			compilation.hooks.addEntry.tap(PLUGIN_NAME, (_, { name: entryName }) => { | 
					
						
							|  |  |  | 				if (entryName === undefined) return; | 
					
						
							|  |  |  | 				const data = | 
					
						
							|  |  |  | 					/** @type {EntryData} */ | 
					
						
							|  |  |  | 					(compilation.entries.get(entryName)); | 
					
						
							|  |  |  | 				if (data.options.runtime === undefined && !data.options.dependOn) { | 
					
						
							|  |  |  | 					// Determine runtime chunk name
 | 
					
						
							|  |  |  | 					let name = | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 						/** @type {string | RuntimeChunkFunction} */ | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 						(this.options.name); | 
					
						
							|  |  |  | 					if (typeof name === "function") { | 
					
						
							|  |  |  | 						name = name({ name: entryName }); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					data.options.runtime = name; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = RuntimeChunkPlugin; |