| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:50:18 +08:00
										 |  |  | const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-20 17:33:02 +08:00
										 |  |  | const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-11-18 19:59:33 +08:00
										 |  |  | const DefinePropertyGetterRuntimeModule = require("./runtime/DefinePropertyGetterRuntimeModule"); | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | const DEPENDENCIES = { | 
					
						
							|  |  |  | 	[RuntimeGlobals.chunkName]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.compatGetDefaultExport]: [ | 
					
						
							|  |  |  | 		RuntimeGlobals.require, | 
					
						
							|  |  |  | 		RuntimeGlobals.definePropertyGetter | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 	[RuntimeGlobals.createFakeNamespaceObject]: [ | 
					
						
							|  |  |  | 		RuntimeGlobals.require, | 
					
						
							|  |  |  | 		RuntimeGlobals.definePropertyGetter, | 
					
						
							|  |  |  | 		RuntimeGlobals.makeNamespaceObject | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 	[RuntimeGlobals.definePropertyGetter]: [RuntimeGlobals.require], | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	[RuntimeGlobals.ensureChunk]: [RuntimeGlobals.require], | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 	[RuntimeGlobals.entryModuleId]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.getFullHash]: [RuntimeGlobals.require], | 
					
						
							| 
									
										
										
										
											2018-12-06 19:11:01 +08:00
										 |  |  | 	[RuntimeGlobals.global]: [RuntimeGlobals.require], | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 	[RuntimeGlobals.makeNamespaceObject]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.moduleCache]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.moduleFactories]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.publicPath]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.scriptNonce]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.uncaughtErrorHandler]: [RuntimeGlobals.require], | 
					
						
							| 
									
										
										
										
											2019-05-24 18:30:43 +08:00
										 |  |  | 	[RuntimeGlobals.wasmInstances]: [RuntimeGlobals.require], | 
					
						
							|  |  |  | 	[RuntimeGlobals.instantiateWasm]: [RuntimeGlobals.require] | 
					
						
							| 
									
										
										
										
											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 => { | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 			for (const req of Object.keys(DEPENDENCIES)) { | 
					
						
							|  |  |  | 				const deps = DEPENDENCIES[req]; | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInModule | 
					
						
							|  |  |  | 					.for(req) | 
					
						
							|  |  |  | 					.tap("RuntimePlugin", (module, 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 | 
					
						
							|  |  |  | 				.for(RuntimeGlobals.definePropertyGetter) | 
					
						
							|  |  |  | 				.tap("RuntimePlugin", chunk => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new DefinePropertyGetterRuntimeModule() | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					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 => { | 
					
						
							|  |  |  | 					compilation.addRuntimeModule( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						new PublicPathRuntimeModule(compilation) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					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( | 
					
						
							|  |  |  | 							compilation, | 
					
						
							|  |  |  | 							chunk, | 
					
						
							|  |  |  | 							"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( | 
					
						
							|  |  |  | 							compilation, | 
					
						
							|  |  |  | 							chunk, | 
					
						
							|  |  |  | 							"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( | 
					
						
							|  |  |  | 							compilation, | 
					
						
							|  |  |  | 							"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); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = RuntimePlugin; |