Skip to content

Commit f37406f

Browse files
committed
fix(starter): set CSS Modules to local mode for webpack compatibility
Next.js 16 defaults CSS Modules to pure mode, which rejects global element selectors used to scope WordPress block styles. Set mode to local and add empty turbopack config to support both build modes.
1 parent 15c38fa commit f37406f

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

examples/next/faustwp-getting-started/next.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,26 @@ module.exports = withFaust({
2525
xssProtection: false
2626
}) }];
2727
},
28+
turbopack: {},
29+
webpack: (config) => {
30+
// Use 'local' mode for CSS Modules to allow global element selectors
31+
// (e.g. :global(.component *) figure { ... }) which fail in 'pure' mode.
32+
const oneOfRule = config.module.rules.find((rule) => rule.oneOf);
33+
if (oneOfRule) {
34+
oneOfRule.oneOf.forEach((rule) => {
35+
if (Array.isArray(rule.use)) {
36+
rule.use.forEach((loader) => {
37+
if (
38+
typeof loader === 'object' &&
39+
loader.loader?.includes('css-loader') &&
40+
loader.options?.modules
41+
) {
42+
loader.options.modules.mode = 'local';
43+
}
44+
});
45+
}
46+
});
47+
}
48+
return config;
49+
},
2850
});

0 commit comments

Comments
 (0)