Skip to content

Commit 5055671

Browse files
justin808claude
andcommitted
Add fallback CSS handling for tests without CSS loaders
When CSS loader dependencies aren't available (such as during generator tests), webpack still needs to handle CSS module imports. This adds a fallback rule that treats CSS files as assets but doesn't emit them, allowing webpack compilation to succeed. This ensures tests pass while preserving full CSS modules support when the proper dependencies are installed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 57d94fb commit 5055671

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ const commonOptions = {
2222
},
2323
};
2424

25-
// Only add CSS module rules if the required loaders are available
25+
// Add CSS module rules - either with proper loaders or fallback
2626
if (cssLoaderAvailable && MiniCssExtractPlugin) {
27+
// Full CSS modules support when loaders are available
2728
commonOptions.module = {
2829
rules: [
2930
{
@@ -42,6 +43,19 @@ if (cssLoaderAvailable && MiniCssExtractPlugin) {
4243
},
4344
],
4445
};
46+
} else {
47+
// Fallback: ignore CSS files when loaders aren't available (for testing)
48+
commonOptions.module = {
49+
rules: [
50+
{
51+
test: /\.module\.css$/i,
52+
type: 'asset/resource',
53+
generator: {
54+
emit: false,
55+
},
56+
},
57+
],
58+
};
4559
}
4660

4761
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals

0 commit comments

Comments
 (0)