Skip to content

Commit 0bd1017

Browse files
justin808claude
andcommitted
Fix CSS modules fallback with identity proxy loader
The previous fallback wasn't providing the named exports that CSS modules require. This fix uses an inline data URI loader to provide a Proxy object that returns any property name as a string, allowing CSS module imports like `import * as styles from './file.module.css'` to work in test environments where CSS loaders aren't available. The proxy returns the property name as-is for named imports (e.g., `styles.bright` returns "bright") and returns itself for default imports, making it work with both import patterns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5055671 commit 0bd1017

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ if (cssLoaderAvailable && MiniCssExtractPlugin) {
4444
],
4545
};
4646
} else {
47-
// Fallback: ignore CSS files when loaders aren't available (for testing)
47+
// Fallback: provide identity object for CSS modules (for testing)
4848
commonOptions.module = {
4949
rules: [
5050
{
5151
test: /\.module\.css$/i,
52-
type: 'asset/resource',
53-
generator: {
54-
emit: false,
55-
},
52+
type: 'javascript/auto',
53+
loader: 'data:text/javascript,module.exports=new Proxy({},{get:function(target,prop){return prop==="default"?this:prop}})',
5654
},
5755
],
5856
};

0 commit comments

Comments
 (0)