Skip to content

Commit 2a7ee5e

Browse files
justin808claude
andcommitted
Improve CSS Modules backward compatibility documentation
Add complete working example to v9 upgrade guide showing how to restore v8 CSS Modules behavior using webpack configuration. This addresses the documentation gap where users needed to figure out the exact configuration on their own. The example includes: - Complete working webpack config code - Detailed explanation of each step - Key points about file extensions and validation - Clear note that this is a temporary solution Fixes #809 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1c13a1a commit 2a7ee5e

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

docs/v9_upgrade.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,55 @@ import * as styles from './Component.module.css';
155155
This allows you to keep using default imports while migrating gradually
156156
157157
3. **Keep v8 behavior** using webpack configuration (Advanced):
158-
- Override the css-loader configuration as shown in [CSS Modules Export Mode documentation](./css-modules-export-mode.md)
159-
- Provides more control over the configuration
158+
159+
If you need more control over the configuration, you can override the css-loader settings directly in your webpack config:
160+
161+
```javascript
162+
// config/webpack/commonWebpackConfig.js (or similar)
163+
const { generateWebpackConfig, merge } = require("shakapacker")
164+
165+
const commonWebpackConfig = () => {
166+
const config = merge({}, generateWebpackConfig())
167+
168+
// Override CSS Modules to use default exports (v8 behavior)
169+
config.module.rules.forEach((rule) => {
170+
if (
171+
rule.test &&
172+
(rule.test.test("example.module.scss") ||
173+
rule.test.test("example.module.css"))
174+
) {
175+
if (Array.isArray(rule.use)) {
176+
rule.use.forEach((loader) => {
177+
if (
178+
loader.loader &&
179+
loader.loader.includes("css-loader") &&
180+
loader.options &&
181+
loader.options.modules
182+
) {
183+
// Disable named exports to support default imports
184+
loader.options.modules.namedExport = false
185+
loader.options.modules.exportLocalsConvention = "camelCase"
186+
}
187+
})
188+
}
189+
}
190+
})
191+
192+
return config
193+
}
194+
195+
module.exports = commonWebpackConfig
196+
```
197+
198+
**Key points:**
199+
- Test both `.module.scss` and `.module.css` file extensions
200+
- Validate all loader properties exist before accessing them
201+
- Use `.includes('css-loader')` since the loader path may vary
202+
- Set both `namedExport: false` and `exportLocalsConvention: 'camelCase'` for full v8 compatibility
203+
204+
**Note:** This is a temporary solution. The recommended approach is to migrate your imports to use named exports as shown in the main documentation.
205+
206+
For detailed configuration options, see the [CSS Modules Export Mode documentation](./css-modules-export-mode.md)
160207

161208
**Benefits of the change:**
162209

0 commit comments

Comments
 (0)