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

Method apply

lib/DynamicEntryPlugin.js:40–92  ·  lib/DynamicEntryPlugin.js::DynamicEntryPlugin.apply

* 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

38 * @returns {void}
39 */
40 apply(compiler) {
41 compiler.hooks.compilation.tap(
42 PLUGIN_NAME,
43 (compilation, { normalModuleFactory }) => {
44 compilation.dependencyFactories.set(
45 EntryDependency,
46 normalModuleFactory
47 );
48 }
49 );
50
51 compiler.hooks.make.tapPromise(PLUGIN_NAME, (compilation) =>
52 Promise.resolve(this.entry())
53 .then((entry) => {
54 /** @type {Promise<void>[]} */
55 const promises = [];
56 for (const name of Object.keys(entry)) {
57 const desc = entry[name];
58 const options = EntryOptionPlugin.entryDescriptionToOptions(
59 compiler,
60 name,
61 desc
62 );
63 for (const entry of /** @type {NonNullable<EntryDescriptionNormalized[class="st">"import"]>} */ (
64 desc.import
65 )) {
66 promises.push(
67 new Promise(
68 /**
69 * Handles the callback logic for this hook.
70 * @param {(value?: undefined) => void} resolve resolve
71 * @param {(reason?: Error) => void} reject reject
72 */
73 (resolve, reject) => {
74 compilation.addEntry(
75 this.context,
76 EntryPlugin.createDependency(entry, options),
77 options,
78 (err) => {
79 if (err) return reject(err);
80 resolve();
81 }
82 );
83 }
84 )
85 );
86 }
87 }
88 return Promise.all(promises);
89 })
90 .then(() => {})
91 );
92 }
93}
94
95module.exports = DynamicEntryPlugin;

Callers

nothing calls this directly

Calls 9

resolveFunction · 0.85
tapMethod · 0.80
addEntryMethod · 0.80
createDependencyMethod · 0.80
resolveMethod · 0.65
keysMethod · 0.65
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected