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

Method apply

lib/ExternalsPlugin.js:37–92  ·  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

35 * @returns {void}
36 */
37 apply(compiler) {
38 compiler.hooks.compile.tap(PLUGIN_NAME, ({ normalModuleFactory }) => {
39 new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
40 normalModuleFactory
41 );
42 });
43
44 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
45 const { concatenatedModuleInfo } =
46 ConcatenatedModule.getCompilationHooks(compilation);
47 concatenatedModuleInfo.tap(PLUGIN_NAME, (updatedInfo, moduleInfo) => {
48 const rawExportMap = updatedInfo.rawExportMap;
49
50 if (!rawExportMap) {
51 return;
52 }
53
54 const chunkInitFragments = moduleInfo.chunkInitFragments;
55 const moduleExternalInitFragments =
56 /** @type {ModuleExternalInitFragment[]} */
57 (
58 chunkInitFragments
59 ? /** @type {unknown[]} */
60 (chunkInitFragments).filter(
61 (fragment) => fragment instanceof ModuleExternalInitFragment
62 )
63 : []
64 );
65
66 let initFragmentChanged = false;
67
68 for (const fragment of moduleExternalInitFragments) {
69 const imported = fragment.getImported();
70
71 if (Array.isArray(imported)) {
72 const newImported =
73 /** @type {Imported} */
74 (
75 imported.map(([specifier, finalName]) => [
76 specifier,
77 rawExportMap.has(specifier)
78 ? rawExportMap.get(specifier)
79 : finalName
80 ])
81 );
82 fragment.setImported(newImported);
83 initFragmentChanged = true;
84 }
85 }
86
87 if (initFragmentChanged) {
88 return true;
89 }
90 });
91 });
92 }
93}
94

Callers

nothing calls this directly

Calls 8

tapMethod · 0.80
getImportedMethod · 0.80
isArrayMethod · 0.80
setImportedMethod · 0.80
applyMethod · 0.65
getCompilationHooksMethod · 0.45
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected