MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/esm/ModuleChunkLoadingPlugin.js:24–141  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 4

tapMethod · 0.80
addRuntimeModuleMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected