From 0f7d26f5dcc8deb865f95c1bb2530cdd0b09afb1 Mon Sep 17 00:00:00 2001 From: Aleksey Smirnov Date: Wed, 23 Oct 2024 19:27:00 +0400 Subject: [PATCH] Use new ChunkGraph Api Drop webpack wornings: 1. [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] 2. [DEP_WEBPACK_CHUNK_GET_MODULES] --- ExposeRuntimeCssAssetsPlugin.cjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ExposeRuntimeCssAssetsPlugin.cjs b/ExposeRuntimeCssAssetsPlugin.cjs index 397f5ce..3495ebd 100644 --- a/ExposeRuntimeCssAssetsPlugin.cjs +++ b/ExposeRuntimeCssAssetsPlugin.cjs @@ -4,6 +4,7 @@ const Template = require("webpack/lib/Template"); const { RuntimeGlobals } = require("webpack"); const { MODULE_TYPE } = require("mini-css-extract-plugin/dist/utils"); +/** @typedef {import("webpack").Compiler} Compiler */ const pluginName = "SingleSpaExposeRuntimeCssAssetsPlugin"; class ExposedCssRuntimeModule extends RuntimeModule { @@ -23,10 +24,14 @@ module.exports = class ExposeRuntimeCssAssetsPlugin { constructor(options) { this.options = options; } + + /** + * @param {Compiler} compiler + */ apply(compiler) { compiler.hooks.compilation.tap(pluginName, (compilation) => { + const { outputOptions, chunkGraph } = compilation; compilation.hooks.contentHash.tap(pluginName, (chunk) => { - const { outputOptions, chunkGraph } = compilation; const modules = chunkGraph.getChunkModulesIterableBySourceType( chunk, MODULE_TYPE @@ -49,9 +54,9 @@ module.exports = class ExposeRuntimeCssAssetsPlugin { compilation.hooks.afterOptimizeChunks.tap(pluginName, (chunks) => { chunks.forEach((chunk) => { - if (chunk.hasEntryModule()) { + if (chunkGraph.getNumberOfEntryModules(chunk) > 0) { let foundCssModule = false; - for (let module of chunk.getModules()) { + for (let module of chunkGraph.getChunkModules(chunk)) { if (module.type === MODULE_TYPE) { foundCssModule = true; break;