* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 22 | * @returns {void} |
| 23 | */ |
| 24 | apply(compiler) { |
| 25 | compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { |
| 26 | const globalChunkLoading = compilation.outputOptions.chunkLoading; |
| 27 | /** |
| 28 | * Checks whether this module chunk loading plugin is enabled for chunk. |
| 29 | * @param {Chunk} chunk chunk to check |
| 30 | * @returns {boolean} true, when the plugin is enabled for the chunk |
| 31 | */ |
| 32 | const isEnabledForChunk = (chunk) => { |
| 33 | const options = chunk.getEntryOptions(); |
| 34 | const chunkLoading = |
| 35 | options && options.chunkLoading !== undefined |
| 36 | ? options.chunkLoading |
| 37 | : globalChunkLoading; |
| 38 | return chunkLoading === "import"; |
| 39 | }; |
| 40 | /** @type {WeakSet<Chunk>} */ |
| 41 | const onceForChunkSet = new WeakSet(); |
| 42 | /** |
| 43 | * Handles the hook callback for this code path. |
| 44 | * @param {Chunk} chunk chunk to check |
| 45 | * @param {RuntimeRequirements} set runtime requirements |
| 46 | */ |
| 47 | const handler = (chunk, set) => { |
| 48 | if (onceForChunkSet.has(chunk)) return; |
| 49 | onceForChunkSet.add(chunk); |
| 50 | if (!isEnabledForChunk(chunk)) return; |
| 51 | set.add(RuntimeGlobals.moduleFactoriesAddOnly); |
| 52 | set.add(RuntimeGlobals.hasOwnProperty); |
| 53 | compilation.addRuntimeModule( |
| 54 | chunk, |
| 55 | new ModuleChunkLoadingRuntimeModule(set) |
| 56 | ); |
| 57 | }; |
| 58 | compilation.hooks.runtimeRequirementInTree |
| 59 | .for(RuntimeGlobals.ensureChunkHandlers) |
| 60 | .tap(PLUGIN_NAME, handler); |
| 61 | compilation.hooks.runtimeRequirementInTree |
| 62 | .for(RuntimeGlobals.baseURI) |
| 63 | .tap(PLUGIN_NAME, handler); |
| 64 | compilation.hooks.runtimeRequirementInTree |
| 65 | .for(RuntimeGlobals.externalInstallChunk) |
| 66 | .tap(PLUGIN_NAME, handler); |
| 67 | compilation.hooks.runtimeRequirementInTree |
| 68 | .for(RuntimeGlobals.onChunksLoaded) |
| 69 | .tap(PLUGIN_NAME, handler); |
| 70 | compilation.hooks.runtimeRequirementInTree |
| 71 | .for(RuntimeGlobals.hmrDownloadUpdateHandlers) |
| 72 | .tap(PLUGIN_NAME, handler); |
| 73 | compilation.hooks.runtimeRequirementInTree |
| 74 | .for(RuntimeGlobals.hmrDownloadManifest) |
| 75 | .tap(PLUGIN_NAME, handler); |
| 76 | compilation.hooks.runtimeRequirementInTree |
| 77 | .for(RuntimeGlobals.externalInstallChunk) |
| 78 | .tap(PLUGIN_NAME, (chunk) => { |
| 79 | if (!isEnabledForChunk(chunk)) return; |
| 80 | compilation.addRuntimeModule( |
| 81 | chunk, |
nothing calls this directly
no test coverage detected