| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							|  |  |  | const JsonpChunkLoadingRuntimeModule = require("./JsonpChunkLoadingRuntimeModule"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class JsonpChunkLoadingPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.thisCompilation.tap( | 
					
						
							|  |  |  | 			"JsonpChunkLoadingPlugin", | 
					
						
							|  |  |  | 			compilation => { | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 				const globalChunkLoading = compilation.outputOptions.chunkLoading; | 
					
						
							|  |  |  | 				const isEnabledForChunk = chunk => { | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | 					const options = chunk.getEntryOptions(); | 
					
						
							| 
									
										
										
										
											2020-08-26 03:45:56 +08:00
										 |  |  | 					const chunkLoading = | 
					
						
							| 
									
										
										
										
											2021-04-15 02:21:17 +08:00
										 |  |  | 						options && options.chunkLoading !== undefined | 
					
						
							|  |  |  | 							? options.chunkLoading | 
					
						
							|  |  |  | 							: globalChunkLoading; | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 					return chunkLoading === "jsonp"; | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | 				const onceForChunkSet = new WeakSet(); | 
					
						
							|  |  |  | 				const handler = (chunk, set) => { | 
					
						
							|  |  |  | 					if (onceForChunkSet.has(chunk)) return; | 
					
						
							|  |  |  | 					onceForChunkSet.add(chunk); | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 					if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | 					set.add(RuntimeGlobals.moduleFactoriesAddOnly); | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.hasOwnProperty); | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new JsonpChunkLoadingRuntimeModule(set) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.ensureChunkHandlers) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", handler); | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", handler); | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hmrDownloadManifest) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", handler); | 
					
						
							| 
									
										
										
										
											2020-08-29 04:39:07 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.baseURI) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", handler); | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.onChunksLoaded) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", handler); | 
					
						
							| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.ensureChunkHandlers) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 						if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | 						set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.loadScript); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.getChunkScriptFilename); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 						if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | 						set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.loadScript); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.moduleCache); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.hmrModuleData); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.moduleFactoriesAddOnly); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hmrDownloadManifest) | 
					
						
							|  |  |  | 					.tap("JsonpChunkLoadingPlugin", (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2020-08-25 19:37:40 +08:00
										 |  |  | 						if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2020-08-25 19:20:29 +08:00
										 |  |  | 						set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.getUpdateManifestFilename); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = JsonpChunkLoadingPlugin; |