Skip to content

Commit faa813e

Browse files
justin808claude
andcommitted
Fix CSS modules webpack loader syntax error
The previous data URI loader approach violated webpack's modern syntax rules. This fix uses NormalModuleReplacementPlugin instead to replace CSS module imports with a mock proxy object that provides identity mapping for any property access. This approach works with webpack 5's stricter loader rules while still providing the necessary fallback behavior for test environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 0bd1017 commit faa813e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ if (cssLoaderAvailable && MiniCssExtractPlugin) {
4444
],
4545
};
4646
} else {
47-
// Fallback: provide identity object for CSS modules (for testing)
48-
commonOptions.module = {
49-
rules: [
50-
{
51-
test: /\.module\.css$/i,
52-
type: 'javascript/auto',
53-
loader: 'data:text/javascript,module.exports=new Proxy({},{get:function(target,prop){return prop==="default"?this:prop}})',
54-
},
55-
],
56-
};
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,module.exports = new Proxy({}, {get: function(target, prop) {return prop === "default" ? this : prop;}})'
55+
)
56+
);
5757
}
5858

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

0 commit comments

Comments
 (0)