Skip to content

Commit 67428aa

Browse files
justin808claude
andcommitted
Revert webpack CSS modules configuration changes
The webpack configuration works correctly in production. The issue was not with the webpack config itself, but with the test environment not having the CSS dependencies properly installed. This reverts back to the clean CSS modules configuration that works in real applications. The actual issue needs to be fixed in how the generator tests handle dependency installation timing, not by modifying the webpack config that users will receive. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 04c8b91 commit 67428aa

File tree

1 file changed

+5
-45
lines changed

1 file changed

+5
-45
lines changed

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

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,15 @@
22

33
// Common configuration applying to client and server configuration
44
const { generateWebpackConfig, merge } = require('shakapacker');
5-
6-
// Try to load CSS plugins, but gracefully handle if they're not installed
7-
let MiniCssExtractPlugin;
8-
let cssLoaderAvailable = true;
9-
try {
10-
MiniCssExtractPlugin = require('mini-css-extract-plugin');
11-
require.resolve('css-loader');
12-
require.resolve('style-loader');
13-
} catch (error) {
14-
cssLoaderAvailable = false;
15-
}
5+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
166

177
const baseClientWebpackConfig = generateWebpackConfig();
188

199
const commonOptions = {
2010
resolve: {
2111
extensions: ['.css', '.ts', '.tsx'],
2212
},
23-
};
24-
25-
// Add CSS module rules - either with proper loaders or fallback
26-
if (cssLoaderAvailable && MiniCssExtractPlugin) {
27-
// Full CSS modules support when loaders are available
28-
commonOptions.module = {
13+
module: {
2914
rules: [
3015
{
3116
test: /\.module\.css$/i,
@@ -42,35 +27,10 @@ if (cssLoaderAvailable && MiniCssExtractPlugin) {
4227
],
4328
},
4429
],
45-
};
46-
} else {
47-
// Fallback: replace CSS module imports with a mock module (for testing)
48-
const webpack = require('webpack');
49-
50-
commonOptions.plugins = commonOptions.plugins || [];
51-
commonOptions.plugins.push(
52-
new webpack.NormalModuleReplacementPlugin(
53-
/\.module\.css$/,
54-
'data:text/javascript,' + encodeURIComponent(`
55-
// For import * as styles, we need to export specific named exports
56-
// Since we don't know the class names, we can't use Proxy with import *
57-
// Instead, export common CSS class names and a default
58-
export const bright = "bright";
59-
export const dark = "dark";
60-
export const container = "container";
61-
export const title = "title";
62-
export const button = "button";
63-
export const input = "input";
64-
export const form = "form";
65-
66-
const styles = { bright: "bright", dark: "dark", container: "container", title: "title", button: "button", input: "input", form: "form" };
67-
export default styles;
68-
`)
69-
)
70-
);
71-
}
30+
},
31+
};
7232

7333
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
7434
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions);
7535

76-
module.exports = commonWebpackConfig;
36+
module.exports = commonWebpackConfig;

0 commit comments

Comments
 (0)