Commit 272cb11
Add css_modules_export_mode configuration option (#817)
## Summary
Introduces a simple, user-friendly configuration option to control CSS
Modules export mode, making it much easier to restore v8 behavior
without manual webpack configuration overrides.
## Problem Solved
Issue #809 identified that upgrading from Shakapacker v8 to v9 requires
complex webpack configuration overrides to maintain v8 CSS Modules
behavior. This creates a high barrier for teams with large codebases who
need to migrate gradually.
## Solution
Add a `css_modules_export_mode` configuration option to
`shakapacker.yml`:
```yaml
# config/shakapacker.yml
default: &default
# CSS Modules export mode
# 'named' (default) - Use named exports with camelCase conversion (v9 default)
# 'default' - Use default export with both original and camelCase names (v8 behavior)
css_modules_export_mode: "named"
```
## Changes
1. **Configuration Schema** (`lib/install/config/shakapacker.yml`)
- Added `css_modules_export_mode` option with clear documentation
- Defaults to `"named"` to maintain v9 behavior
2. **TypeScript Types** (`package/types.ts`)
- Added `css_modules_export_mode?: "named" | "default"` to Config
interface
- Provides type safety and IDE autocomplete
3. **Implementation** (`package/utils/getStyleRule.ts`)
- Reads configuration and applies appropriate CSS loader settings
- `"named"`: Sets `namedExport: true` and `exportLocalsConvention:
"camelCaseOnly"` (v9 default)
- `"default"`: Sets `namedExport: false` and `exportLocalsConvention:
"camelCase"` (v8 behavior)
4. **Documentation Updates**
- Updated `docs/css-modules-export-mode.md` with new configuration
approach
- Updated `docs/v9_upgrade.md` to highlight the simple config option
first
- Reorganized migration options to emphasize the easiest approach
## Benefits
- **No webpack expertise required** - Users just change one line in YAML
- **Reduced migration friction** - Large codebases can upgrade
immediately
- **Clear migration path** - Simple to enable v8 mode, then gradually
migrate
- **Maintains best practices** - Defaults to v9 behavior, but provides
escape hatch
- **Better than PR #810** - While that PR improved documentation, this
provides a programmatic solution
## Example Usage
### Keeping v8 Behavior
```yaml
# config/shakapacker.yml
css_modules_export_mode: "default"
```
Then continue using v8-style imports:
```javascript
import styles from './Component.module.css';
<button className={styles.button} />
```
### Using v9 Behavior (Default)
```yaml
# config/shakapacker.yml
css_modules_export_mode: "named" # or omit this line
```
Use v9-style imports:
```javascript
// JavaScript
import { button } from './Component.module.css';
<button className={button} />
// TypeScript
import * as styles from './Component.module.css';
<button className={styles.button} />
```
## Migration Strategy
1. **Immediate upgrade**: Set `css_modules_export_mode: "default"` to
maintain v8 behavior
2. **Gradual migration**: Update components incrementally to use named
exports
3. **Complete migration**: Remove the config option to use v9 default
## Test Plan
- [x] Linting passes (`yarn lint`)
- [x] RuboCop passes (`bundle exec rubocop`)
- [x] TypeScript type checking passes (`yarn run tsc --noEmit`)
- [x] Configuration is properly typed
- [x] Documentation is clear and comprehensive
## Related
- Addresses issue #809
- Complements PR #810 (documentation improvements)
- Supersedes manual webpack configuration approach
Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added a configurable CSS Modules export mode allowing projects to use
either v8-style default imports or v9-style named exports.
* **Documentation**
* Expanded upgrade and CSS Modules guides with step-by-step
configuration examples and migration options (easy config-driven or
advanced manual approaches).
* **Tests**
* Updated test coverage to validate mode-dependent CSS Modules behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude <[email protected]>1 parent 10d2164 commit 272cb11
File tree
8 files changed
+150
-21
lines changed- docs
- lib
- install/config
- shakapacker
- package
- utils
- spec/shakapacker
8 files changed
+150
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
158 | 192 | | |
159 | 193 | | |
160 | 194 | | |
| |||
198 | 232 | | |
199 | 233 | | |
200 | 234 | | |
201 | | - | |
| 235 | + | |
202 | 236 | | |
203 | 237 | | |
204 | 238 | | |
| |||
239 | 273 | | |
240 | 274 | | |
241 | 275 | | |
242 | | - | |
| 276 | + | |
243 | 277 | | |
244 | 278 | | |
245 | 279 | | |
246 | 280 | | |
247 | | - | |
| 281 | + | |
248 | 282 | | |
249 | 283 | | |
250 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
149 | 158 | | |
150 | | - | |
| 159 | + | |
151 | 160 | | |
152 | 161 | | |
153 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
22 | 34 | | |
23 | 35 | | |
24 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
342 | 367 | | |
343 | 368 | | |
344 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | | - | |
188 | | - | |
| 188 | + | |
| 189 | + | |
189 | 190 | | |
190 | | - | |
191 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
192 | 195 | | |
193 | | - | |
194 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
195 | 235 | | |
196 | 236 | | |
197 | 237 | | |
| |||
0 commit comments