* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 73 | * @returns {void} |
| 74 | */ |
| 75 | apply(compiler) { |
| 76 | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| 77 | compiler.validate( |
| 78 | () => |
| 79 | require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json"), |
| 80 | this.options, |
| 81 | { |
| 82 | name: "Aggressive Splitting Plugin", |
| 83 | baseDataPath: "options" |
| 84 | }, |
| 85 | (options) => |
| 86 | require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.check")( |
| 87 | options |
| 88 | ) |
| 89 | ); |
| 90 | }); |
| 91 | |
| 92 | compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { |
| 93 | let needAdditionalSeal = false; |
| 94 | /** @type {SplitData[]} */ |
| 95 | let newSplits; |
| 96 | /** @type {Set<Chunk>} */ |
| 97 | let fromAggressiveSplittingSet; |
| 98 | /** @type {Map<Chunk, SplitData>} */ |
| 99 | let chunkSplitDataMap; |
| 100 | compilation.hooks.optimize.tap(PLUGIN_NAME, () => { |
| 101 | newSplits = []; |
| 102 | fromAggressiveSplittingSet = new Set(); |
| 103 | chunkSplitDataMap = new Map(); |
| 104 | }); |
| 105 | compilation.hooks.optimizeChunks.tap( |
| 106 | { |
| 107 | name: PLUGIN_NAME, |
| 108 | stage: STAGE_ADVANCED |
| 109 | }, |
| 110 | (chunks) => { |
| 111 | const chunkGraph = compilation.chunkGraph; |
| 112 | // Precompute stuff |
| 113 | /** @type {Map<string, Module>} */ |
| 114 | const nameToModuleMap = new Map(); |
| 115 | /** @type {Map<Module, string>} */ |
| 116 | const moduleToNameMap = new Map(); |
| 117 | const makePathsRelative = |
| 118 | identifierUtils.makePathsRelative.bindContextCache( |
| 119 | compiler.context, |
| 120 | compiler.root |
| 121 | ); |
| 122 | for (const m of compilation.modules) { |
| 123 | const name = makePathsRelative(m.identifier()); |
| 124 | nameToModuleMap.set(name, m); |
| 125 | moduleToNameMap.set(m, name); |
| 126 | } |
| 127 | |
| 128 | // Check used chunk ids |
| 129 | /** @type {Set<ChunkId>} */ |
| 130 | const usedIds = new Set(); |
| 131 | for (const chunk of chunks) { |
| 132 | usedIds.add(/** @type {ChunkId} */ (chunk.id)); |
nothing calls this directly
no test coverage detected