| 
									
										
										
										
											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"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | class RuntimeChunkPlugin { | 
					
						
							| 
									
										
										
										
											2018-01-26 01:52:36 +08:00
										 |  |  | 	constructor(options) { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		this.options = { | 
					
						
							|  |  |  | 			name: entrypoint => `runtime~${entrypoint.name}`, | 
					
						
							|  |  |  | 			...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) { | 
					
						
							| 
									
										
										
										
											2018-01-24 19:00:50 +08:00
										 |  |  | 		compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => { | 
					
						
							| 
									
										
										
										
											2020-07-21 16:22:10 +08:00
										 |  |  | 			compilation.hooks.addEntry.tap( | 
					
						
							|  |  |  | 				"RuntimeChunkPlugin", | 
					
						
							|  |  |  | 				(_, { name: entryName }) => { | 
					
						
							| 
									
										
										
										
											2020-10-08 06:28:30 +08:00
										 |  |  | 					if (entryName === undefined) return; | 
					
						
							| 
									
										
										
										
											2020-07-21 16:22:10 +08:00
										 |  |  | 					const data = compilation.entries.get(entryName); | 
					
						
							| 
									
										
										
										
											2020-07-31 21:14:49 +08:00
										 |  |  | 					if (!data.options.runtime && !data.options.dependOn) { | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 						// Determine runtime chunk name
 | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | 						let name = this.options.name; | 
					
						
							|  |  |  | 						if (typeof name === "function") { | 
					
						
							| 
									
										
										
										
											2020-07-21 16:22:10 +08:00
										 |  |  | 							name = name({ name: entryName }); | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-07-21 16:22:10 +08:00
										 |  |  | 						data.options.runtime = name; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = RuntimeChunkPlugin; |