| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("./RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2019-10-07 17:16:38 +08:00
										 |  |  | const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency"); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:50:18 +08:00
										 |  |  | const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | const CompatRuntimePlugin = require("./runtime/CompatRuntimePlugin"); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:33:02 +08:00
										 |  |  | const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2019-08-23 20:07:01 +08:00
										 |  |  | const DefinePropertyGettersRuntimeModule = require("./runtime/DefinePropertyGettersRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | const EnsureChunkRuntimeModule = require("./runtime/EnsureChunkRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-21 18:32:10 +08:00
										 |  |  | const GetChunkFilenameRuntimeModule = require("./runtime/GetChunkFilenameRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | const GetMainFilenameRuntimeModule = require("./runtime/GetMainFilenameRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-12-06 19:11:01 +08:00
										 |  |  | const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:22:10 +08:00
										 |  |  | const MakeNamespaceObjectRuntimeModule = require("./runtime/MakeNamespaceObjectRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | const PublicPathRuntimeModule = require("./runtime/PublicPathRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							|  |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | const GLOBALS_ON_REQUIRE = [ | 
					
						
							|  |  |  | 	RuntimeGlobals.chunkName, | 
					
						
							|  |  |  | 	RuntimeGlobals.compatGetDefaultExport, | 
					
						
							|  |  |  | 	RuntimeGlobals.createFakeNamespaceObject, | 
					
						
							|  |  |  | 	RuntimeGlobals.definePropertyGetters, | 
					
						
							|  |  |  | 	RuntimeGlobals.ensureChunk, | 
					
						
							|  |  |  | 	RuntimeGlobals.entryModuleId, | 
					
						
							|  |  |  | 	RuntimeGlobals.getFullHash, | 
					
						
							|  |  |  | 	RuntimeGlobals.global, | 
					
						
							|  |  |  | 	RuntimeGlobals.makeNamespaceObject, | 
					
						
							|  |  |  | 	RuntimeGlobals.moduleCache, | 
					
						
							|  |  |  | 	RuntimeGlobals.moduleFactories, | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 	RuntimeGlobals.moduleFactoriesAddOnly, | 
					
						
							| 
									
										
										
										
											2019-09-30 16:08:08 +08:00
										 |  |  | 	RuntimeGlobals.interceptModuleExecution, | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	RuntimeGlobals.publicPath, | 
					
						
							|  |  |  | 	RuntimeGlobals.scriptNonce, | 
					
						
							|  |  |  | 	RuntimeGlobals.uncaughtErrorHandler, | 
					
						
							|  |  |  | 	RuntimeGlobals.wasmInstances, | 
					
						
							|  |  |  | 	RuntimeGlobals.instantiateWasm | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const TREE_DEPENDENCIES = { | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 	[RuntimeGlobals.compatGetDefaultExport]: [ | 
					
						
							| 
									
										
										
										
											2019-08-23 20:07:01 +08:00
										 |  |  | 		RuntimeGlobals.definePropertyGetters | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 	], | 
					
						
							|  |  |  | 	[RuntimeGlobals.createFakeNamespaceObject]: [ | 
					
						
							| 
									
										
										
										
											2019-08-23 20:07:01 +08:00
										 |  |  | 		RuntimeGlobals.definePropertyGetters, | 
					
						
							| 
									
										
										
										
											2019-09-30 16:08:08 +08:00
										 |  |  | 		RuntimeGlobals.makeNamespaceObject, | 
					
						
							|  |  |  | 		RuntimeGlobals.require | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	] | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class RuntimePlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the Compiler | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap("RuntimePlugin", compilation => { | 
					
						
							| 
									
										
										
										
											2019-10-07 17:16:38 +08:00
										 |  |  | 			compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 				RuntimeRequirementsDependency, | 
					
						
							|  |  |  | 				new RuntimeRequirementsDependency.Template() | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 			for (const req of GLOBALS_ON_REQUIRE) { | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInModule | 
					
						
							|  |  |  | 					.for(req) | 
					
						
							|  |  |  | 					.tap("RuntimePlugin", (module, set) => { | 
					
						
							| 
									
										
										
										
											2019-09-30 16:08:08 +08:00
										 |  |  | 						set.add(RuntimeGlobals.requireScope); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(req) | 
					
						
							|  |  |  | 					.tap("RuntimePlugin", (module, set) => { | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.requireScope); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const req of Object.keys(TREE_DEPENDENCIES)) { | 
					
						
							|  |  |  | 				const deps = TREE_DEPENDENCIES[req]; | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(req) | 
					
						
							|  |  |  | 					.tap("RuntimePlugin", (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 						for (const dep of deps) set.add(dep); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-18 19:59:33 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							| 
									
										
										
										
											2019-08-23 20:07:01 +08:00
										 |  |  | 				.for(RuntimeGlobals.definePropertyGetters) | 
					
						
							| 
									
										
										
										
											2018-11-18 19:59:33 +08:00
										 |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							| 
									
										
										
										
											2019-08-23 20:07:01 +08:00
										 |  |  | 						new DefinePropertyGettersRuntimeModule() | 
					
						
							| 
									
										
										
										
											2018-11-18 19:59:33 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:22:10 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.makeNamespaceObject) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new MakeNamespaceObjectRuntimeModule() | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:33:02 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.createFakeNamespaceObject) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new CreateFakeNamespaceObjectRuntimeModule() | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:50:18 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.compatGetDefaultExport) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new CompatGetDefaultExportRuntimeModule() | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.publicPath) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 					compilation.addRuntimeModule(chunk, new PublicPathRuntimeModule()); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-12-06 19:11:01 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.global) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule(chunk, new GlobalRuntimeModule()); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-21 18:32:10 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.getChunkScriptFilename) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2018-12-26 03:14:58 +08:00
										 |  |  | 					if ( | 
					
						
							|  |  |  | 						/\[(full)?hash(:\d+)?\]/.test( | 
					
						
							|  |  |  | 							compilation.outputOptions.chunkFilename | 
					
						
							|  |  |  | 						) | 
					
						
							|  |  |  | 					) | 
					
						
							| 
									
										
										
										
											2018-11-21 18:32:10 +08:00
										 |  |  | 						set.add(RuntimeGlobals.getFullHash); | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new GetChunkFilenameRuntimeModule( | 
					
						
							|  |  |  | 							"javascript", | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 							"javascript", | 
					
						
							| 
									
										
										
										
											2018-11-21 18:32:10 +08:00
										 |  |  | 							RuntimeGlobals.getChunkScriptFilename, | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 							chunk => | 
					
						
							| 
									
										
										
										
											2019-02-18 17:03:07 +08:00
										 |  |  | 								chunk.filenameTemplate || | 
					
						
							|  |  |  | 								(chunk.isOnlyInitial() | 
					
						
							|  |  |  | 									? compilation.outputOptions.filename | 
					
						
							|  |  |  | 									: compilation.outputOptions.chunkFilename), | 
					
						
							|  |  |  | 							false | 
					
						
							| 
									
										
										
										
											2018-11-21 18:32:10 +08:00
										 |  |  | 						) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.getChunkUpdateScriptFilename) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", (chunk, set) => { | 
					
						
							|  |  |  | 					if ( | 
					
						
							| 
									
										
										
										
											2018-12-26 03:14:58 +08:00
										 |  |  | 						/\[(full)?hash(:\d+)?\]/.test( | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 							compilation.outputOptions.hotUpdateChunkFilename | 
					
						
							|  |  |  | 						) | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.getFullHash); | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new GetChunkFilenameRuntimeModule( | 
					
						
							|  |  |  | 							"javascript", | 
					
						
							|  |  |  | 							"javascript update", | 
					
						
							|  |  |  | 							RuntimeGlobals.getChunkUpdateScriptFilename, | 
					
						
							| 
									
										
										
										
											2019-02-18 17:03:07 +08:00
										 |  |  | 							c => compilation.outputOptions.hotUpdateChunkFilename, | 
					
						
							|  |  |  | 							true | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 						) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.getUpdateManifestFilename) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", (chunk, set) => { | 
					
						
							|  |  |  | 					if ( | 
					
						
							| 
									
										
										
										
											2018-12-26 03:14:58 +08:00
										 |  |  | 						/\[(full)?hash(:\d+)?\]/.test( | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 							compilation.outputOptions.hotUpdateMainFilename | 
					
						
							|  |  |  | 						) | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 					) { | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 						set.add(RuntimeGlobals.getFullHash); | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new GetMainFilenameRuntimeModule( | 
					
						
							|  |  |  | 							"update manifest", | 
					
						
							|  |  |  | 							RuntimeGlobals.getUpdateManifestFilename, | 
					
						
							|  |  |  | 							compilation.outputOptions.hotUpdateMainFilename | 
					
						
							|  |  |  | 						) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.ensureChunk) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", (chunk, set) => { | 
					
						
							|  |  |  | 					const hasAsyncChunks = chunk.hasAsyncChunks(); | 
					
						
							|  |  |  | 					if (hasAsyncChunks) { | 
					
						
							|  |  |  | 						set.add(RuntimeGlobals.ensureChunkHandlers); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 						new EnsureChunkRuntimeModule(set) | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 			compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.ensureChunkIncludeEntries) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", (chunk, set) => { | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.ensureChunkHandlers); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2019-10-04 18:24:52 +08:00
										 |  |  | 			// TODO webpack 6: remove CompatRuntimePlugin
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 			compilation.hooks.additionalTreeRuntimeRequirements.tap( | 
					
						
							|  |  |  | 				"RuntimePlugin", | 
					
						
							|  |  |  | 				(chunk, set) => { | 
					
						
							|  |  |  | 					const { mainTemplate } = compilation; | 
					
						
							|  |  |  | 					if ( | 
					
						
							| 
									
										
										
										
											2019-09-30 16:08:08 +08:00
										 |  |  | 						mainTemplate.hooks.bootstrap.isUsed() || | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 						mainTemplate.hooks.localVars.isUsed() || | 
					
						
							|  |  |  | 						mainTemplate.hooks.requireEnsure.isUsed() || | 
					
						
							|  |  |  | 						mainTemplate.hooks.requireExtensions.isUsed() | 
					
						
							|  |  |  | 					) { | 
					
						
							|  |  |  | 						compilation.addRuntimeModule(chunk, new CompatRuntimePlugin()); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = RuntimePlugin; |