Skip to content

Commit 83faebc

Browse files
justin808claude
andcommitted
Fix CSS Modules configuration for Shakapacker 9.x compatibility
Shakapacker 9 changed the CSS Modules default configuration from default exports to named exports (namedExport: true). This breaks existing code that uses `import styles from './style.module.css'` syntax. This commit adds webpack configuration to override Shakapacker 9's CSS Modules settings and restore backward compatibility with the v8 behavior. Changes: - Override namedExport: false to support default imports - Set exportLocalsConvention: 'camelCase' to match existing usage - Add configuration in Pro dummy commonWebpackConfig - Matches the fix already applied to regular dummy in previous commits This fixes CI test failures where React components weren't rendering because CSS module imports were failing at runtime. Related to Shakapacker upgrade from 8.0.0 to 9.1.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 42d8f98 commit 83faebc

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

react_on_rails_pro/spec/dummy/config/webpack/commonWebpackConfig.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ if (isHMR) {
4848
);
4949
}
5050

51-
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions, aliasConfig);
51+
const commonWebpackConfig = () => {
52+
const config = merge({}, baseClientWebpackConfig, commonOptions, aliasConfig);
53+
54+
// Fix CSS modules for Shakapacker 9.x compatibility
55+
// Shakapacker 9 defaults to namedExport: true, but our code uses default imports
56+
// Override to use the old behavior for backward compatibility
57+
config.module.rules.forEach((rule) => {
58+
if (
59+
rule.test &&
60+
(rule.test.test('example.module.scss') || rule.test.test('example.module.css'))
61+
) {
62+
if (Array.isArray(rule.use)) {
63+
rule.use.forEach((loader) => {
64+
if (
65+
loader.loader &&
66+
loader.loader.includes('css-loader') &&
67+
loader.options &&
68+
loader.options.modules
69+
) {
70+
// Disable named exports to support default imports
71+
// eslint-disable-next-line no-param-reassign
72+
loader.options.modules.namedExport = false;
73+
// eslint-disable-next-line no-param-reassign
74+
loader.options.modules.exportLocalsConvention = 'camelCase';
75+
}
76+
});
77+
}
78+
}
79+
});
80+
81+
return config;
82+
};
5283

5384
module.exports = commonWebpackConfig;

0 commit comments

Comments
 (0)