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

Method apply

lib/ids/ChunkModuleIdRangePlugin.js:44–93  ·  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

42 * @returns {void}
43 */
44 apply(compiler) {
45 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
46 const moduleGraph = compilation.moduleGraph;
47 compilation.hooks.moduleIds.tap(PLUGIN_NAME, (modules) => {
48 const chunkGraph = compilation.chunkGraph;
49 const chunk = find(
50 compilation.chunks,
51 (chunk) => chunk.name === this.options.name
52 );
53 if (!chunk) {
54 throw new Error(
55 `${PLUGIN_NAME}: Chunk with name '${this.options.name}"' was not found`
56 );
57 }
58
59 /** @type {Module[]} */
60 let chunkModules;
61 if (this.options.order) {
62 /** @type {ModuleComparator} */
63 let cmpFn;
64 switch (this.options.order) {
65 case "index":
66 case "preOrderIndex":
67 cmpFn = compareModulesByPreOrderIndexOrIdentifier(moduleGraph);
68 break;
69 case "index2":
70 case "postOrderIndex":
71 cmpFn = compareModulesByPostOrderIndexOrIdentifier(moduleGraph);
72 break;
73 default:
74 throw new Error(`${PLUGIN_NAME}: unexpected value of order`);
75 }
76 chunkModules = chunkGraph.getOrderedChunkModules(chunk, cmpFn);
77 } else {
78 chunkModules = [...modules]
79 .filter((m) => chunkGraph.isModuleInChunk(m, chunk))
80 .sort(compareModulesByPreOrderIndexOrIdentifier(moduleGraph));
81 }
82
83 let currentId = this.options.start || 0;
84 for (let i = 0; i < chunkModules.length; i++) {
85 const m = chunkModules[i];
86 if (m.needId && chunkGraph.getModuleId(m) === null) {
87 chunkGraph.setModuleId(m, currentId++);
88 }
89 if (this.options.end && currentId > this.options.end) break;
90 }
91 });
92 });
93 }
94}
95
96module.exports = ChunkModuleIdRangePlugin;

Callers

nothing calls this directly

Calls 9

tapMethod · 0.80
sortMethod · 0.80
isModuleInChunkMethod · 0.80
getModuleIdMethod · 0.80
setModuleIdMethod · 0.80
findFunction · 0.50

Tested by

no test coverage detected