* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the Compiler * @returns {void}
(compiler)
| 145 | * @returns {void} |
| 146 | */ |
| 147 | apply(compiler) { |
| 148 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 149 | const globalChunkLoading = compilation.outputOptions.chunkLoading; |
| 150 | /** |
| 151 | * Checks whether this runtime plugin is chunk loading disabled for chunk. |
| 152 | * @param {Chunk} chunk chunk |
| 153 | * @returns {boolean} true, when chunk loading is disabled for the chunk |
| 154 | */ |
| 155 | const isChunkLoadingDisabledForChunk = (chunk) => { |
| 156 | const options = chunk.getEntryOptions(); |
| 157 | const chunkLoading = |
| 158 | options && options.chunkLoading !== undefined |
| 159 | ? options.chunkLoading |
| 160 | : globalChunkLoading; |
| 161 | return chunkLoading === false; |
| 162 | }; |
| 163 | compilation.dependencyTemplates.set( |
| 164 | RuntimeRequirementsDependency, |
| 165 | new RuntimeRequirementsDependency.Template() |
| 166 | ); |
| 167 | for (const req of GLOBALS_ON_REQUIRE) { |
| 168 | compilation.hooks.runtimeRequirementInModule |
| 169 | .for(req) |
| 170 | .tap(PLUGIN_NAME, (module, set) => { |
| 171 | set.add(RuntimeGlobals.requireScope); |
| 172 | }); |
| 173 | compilation.hooks.runtimeRequirementInTree |
| 174 | .for(req) |
| 175 | .tap(PLUGIN_NAME, (module, set) => { |
| 176 | set.add(RuntimeGlobals.requireScope); |
| 177 | }); |
| 178 | } |
| 179 | for (const req of Object.keys(TREE_DEPENDENCIES)) { |
| 180 | const deps = |
| 181 | TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)]; |
| 182 | compilation.hooks.runtimeRequirementInTree |
| 183 | .for(req) |
| 184 | .tap(PLUGIN_NAME, (chunk, set) => { |
| 185 | for (const dep of deps) set.add(dep); |
| 186 | }); |
| 187 | } |
| 188 | for (const req of Object.keys(MODULE_DEPENDENCIES)) { |
| 189 | const deps = |
| 190 | MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)]; |
| 191 | compilation.hooks.runtimeRequirementInModule |
| 192 | .for(req) |
| 193 | .tap(PLUGIN_NAME, (chunk, set) => { |
| 194 | for (const dep of deps) set.add(dep); |
| 195 | }); |
| 196 | } |
| 197 | compilation.hooks.runtimeRequirementInTree |
| 198 | .for(RuntimeGlobals.definePropertyGetters) |
| 199 | .tap(PLUGIN_NAME, (chunk) => { |
| 200 | compilation.addRuntimeModule( |
| 201 | chunk, |
| 202 | new DefinePropertyGettersRuntimeModule() |
| 203 | ); |
| 204 | return true; |
nothing calls this directly
no test coverage detected