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

Method apply

lib/optimize/MinChunkSizePlugin.js:31–123  ·  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

29 * @returns {void}
30 */
31 apply(compiler) {
32 compiler.hooks.validate.tap(PLUGIN_NAME, () => {
33 compiler.validate(
34 () => require("../../schemas/plugins/optimize/MinChunkSizePlugin.json"),
35 this.options,
36 {
37 name: "Min Chunk Size Plugin",
38 baseDataPath: "options"
39 },
40 (options) =>
41 require("../../schemas/plugins/optimize/MinChunkSizePlugin.check")(
42 options
43 )
44 );
45 });
46 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
47 compilation.hooks.optimizeChunks.tap(
48 {
49 name: PLUGIN_NAME,
50 stage: STAGE_ADVANCED
51 },
52 (chunks) => {
53 const chunkGraph = compilation.chunkGraph;
54 const equalOptions = {
55 chunkOverhead: 1,
56 entryChunkMultiplicator: 1
57 };
58
59 /** @type {Map<Chunk, number>} */
60 const chunkSizesMap = new Map();
61 /** @type {[Chunk, Chunk][]} */
62 const combinations = [];
63 /** @type {Chunk[]} */
64 const smallChunks = [];
65 /** @type {Chunk[]} */
66 const visitedChunks = [];
67 for (const a of chunks) {
68 // check if one of the chunks sizes is smaller than the minChunkSize
69 // and filter pairs that can NOT be integrated!
70 if (
71 chunkGraph.getChunkSize(a, equalOptions) <
72 this.options.minChunkSize
73 ) {
74 smallChunks.push(a);
75 for (const b of visitedChunks) {
76 if (chunkGraph.canChunksBeIntegrated(b, a)) {
77 combinations.push([b, a]);
78 }
79 }
80 } else {
81 for (const b of smallChunks) {
82 if (chunkGraph.canChunksBeIntegrated(b, a)) {
83 combinations.push([b, a]);
84 }
85 }
86 }
87 chunkSizesMap.set(a, chunkGraph.getChunkSize(a, this.options));
88 visitedChunks.push(a);

Callers

nothing calls this directly

Calls 12

tapMethod · 0.80
validateMethod · 0.80
getChunkSizeMethod · 0.80
canChunksBeIntegratedMethod · 0.80
sortMethod · 0.80
integrateChunksMethod · 0.80
requireFunction · 0.50
pushMethod · 0.45
setMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected