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

Method apply

lib/ids/NamedChunkIdsPlugin.js:43–91  ·  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

41 * @returns {void}
42 */
43 apply(compiler) {
44 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
45 const hashFunction = compilation.outputOptions.hashFunction;
46 compilation.hooks.chunkIds.tap(PLUGIN_NAME, (chunks) => {
47 const chunkGraph = compilation.chunkGraph;
48 const context = this.options.context
49 ? this.options.context
50 : compiler.context;
51 const delimiter = this.options.delimiter || "-";
52
53 const unnamedChunks = assignNames(
54 [...chunks].filter((chunk) => {
55 if (chunk.name) {
56 chunk.id = chunk.name;
57 chunk.ids = [chunk.name];
58 }
59 return chunk.id === null;
60 }),
61 (chunk) =>
62 getShortChunkName(
63 chunk,
64 chunkGraph,
65 context,
66 delimiter,
67 hashFunction,
68 compiler.root
69 ),
70 (chunk) =>
71 getLongChunkName(
72 chunk,
73 chunkGraph,
74 context,
75 delimiter,
76 hashFunction,
77 compiler.root
78 ),
79 compareChunksNatural(chunkGraph),
80 getUsedChunkIds(compilation),
81 (chunk, name) => {
82 chunk.id = name;
83 chunk.ids = [name];
84 }
85 );
86 if (unnamedChunks.length > 0) {
87 assignAscendingChunkIds(unnamedChunks, compilation);
88 }
89 });
90 });
91 }
92}
93
94module.exports = NamedChunkIdsPlugin;

Callers

nothing calls this directly

Calls 7

assignNamesFunction · 0.85
getShortChunkNameFunction · 0.85
getLongChunkNameFunction · 0.85
compareChunksNaturalFunction · 0.85
getUsedChunkIdsFunction · 0.85
assignAscendingChunkIdsFunction · 0.85
tapMethod · 0.80

Tested by

no test coverage detected