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

Method apply

lib/AutomaticPrefetchPlugin.js:27–68  ·  view source on GitHub ↗

* Registers hooks that remember previously built normal modules and enqueue * them as `PrefetchDependency` requests during the next make phase. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

25 * @returns {void}
26 */
27 apply(compiler) {
28 compiler.hooks.compilation.tap(
29 PLUGIN_NAME,
30 (compilation, { normalModuleFactory }) => {
31 compilation.dependencyFactories.set(
32 PrefetchDependency,
33 normalModuleFactory
34 );
35 }
36 );
37 /** @type {{ context: string | null, request: string }[] | null} */
38 let lastModules = null;
39 compiler.hooks.afterCompile.tap(PLUGIN_NAME, (compilation) => {
40 lastModules = [];
41
42 for (const m of compilation.modules) {
43 if (m instanceof NormalModule) {
44 lastModules.push({
45 context: m.context,
46 request: m.request
47 });
48 }
49 }
50 });
51 compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
52 if (!lastModules) return callback();
53 asyncLib.each(
54 lastModules,
55 (m, callback) => {
56 compilation.addModuleChain(
57 m.context || compiler.context,
58 new PrefetchDependency(`!!${m.request}`),
59 callback
60 );
61 },
62 (err) => {
63 lastModules = null;
64 callback(err);
65 }
66 );
67 });
68 }
69}
70
71module.exports = AutomaticPrefetchPlugin;

Callers

nothing calls this directly

Calls 5

tapMethod · 0.80
addModuleChainMethod · 0.80
callbackFunction · 0.50
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected