Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new ChunkGraph Api #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ExposeRuntimeCssAssetsPlugin.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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;
Expand Down
Loading