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

Method apply

lib/ids/OccurrenceModuleIdsPlugin.js:37–172  ·  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.validate.tap(PLUGIN_NAME, () => {
39 compiler.validate(
40 () =>
41 require("../../schemas/plugins/ids/OccurrenceModuleIdsPlugin.json"),
42 this.options,
43 {
44 name: "Occurrence Order Module Ids Plugin",
45 baseDataPath: "options"
46 },
47 (options) =>
48 require("../../schemas/plugins/ids/OccurrenceModuleIdsPlugin.check")(
49 options
50 )
51 );
52 });
53 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
54 const moduleGraph = compilation.moduleGraph;
55
56 compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
57 const chunkGraph = compilation.chunkGraph;
58
59 const [usedIds, modulesInOccurrenceOrder] =
60 getUsedModuleIdsAndModules(compilation);
61
62 /** @type {Map<Module, number>} */
63 const occursInInitialChunksMap = new Map();
64 /** @type {Map<Module, number>} */
65 const occursInAllChunksMap = new Map();
66
67 /** @type {Map<Module, number>} */
68 const initialChunkChunkMap = new Map();
69 /** @type {Map<Module, number>} */
70 const entryCountMap = new Map();
71 for (const m of modulesInOccurrenceOrder) {
72 let initial = 0;
73 let entry = 0;
74 for (const c of chunkGraph.getModuleChunksIterable(m)) {
75 if (c.canBeInitial()) initial++;
76 if (chunkGraph.isEntryModuleInChunk(m, c)) entry++;
77 }
78 initialChunkChunkMap.set(m, initial);
79 entryCountMap.set(m, entry);
80 }
81
82 /**
83 * Count occurs in entry.
84 * @param {Module} module module
85 * @returns {number} count of occurs
86 */
87 const countOccursInEntry = (module) => {
88 let sum = 0;
89 for (const [
90 originModule,
91 connections
92 ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
93 if (!originModule) continue;
94 if (!connections.some((c) => c.isTargetActive(undefined))) continue;

Callers

nothing calls this directly

Calls 13

assignAscendingModuleIdsFunction · 0.85
tapMethod · 0.80
validateMethod · 0.80
canBeInitialMethod · 0.80
isEntryModuleInChunkMethod · 0.80
sortMethod · 0.80
requireFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected