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

Method apply

lib/ids/DeterministicChunkIdsPlugin.js:41–72  ·  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

39 * @returns {void}
40 */
41 apply(compiler) {
42 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
43 compilation.hooks.chunkIds.tap(PLUGIN_NAME, (chunks) => {
44 const chunkGraph = compilation.chunkGraph;
45 const context = this.options.context
46 ? this.options.context
47 : compiler.context;
48 const maxLength = this.options.maxLength || 3;
49
50 const compareNatural = compareChunksNatural(chunkGraph);
51
52 const usedIds = getUsedChunkIds(compilation);
53 assignDeterministicIds(
54 [...chunks].filter((chunk) => chunk.id === null),
55 (chunk) =>
56 getFullChunkName(chunk, chunkGraph, context, compiler.root),
57 compareNatural,
58 (chunk, id) => {
59 const size = usedIds.size;
60 usedIds.add(`${id}`);
61 if (size === usedIds.size) return false;
62 chunk.id = id;
63 chunk.ids = [id];
64 return true;
65 },
66 [10 ** maxLength],
67 10,
68 usedIds.size
69 );
70 });
71 });
72 }
73}
74
75module.exports = DeterministicChunkIdsPlugin;

Callers

nothing calls this directly

Calls 6

compareChunksNaturalFunction · 0.85
getUsedChunkIdsFunction · 0.85
assignDeterministicIdsFunction · 0.85
getFullChunkNameFunction · 0.85
tapMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected