shakapacker 9.3.0 → 9.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/update-changelog.md +232 -0
  3. data/.github/actionlint-matcher.json +17 -0
  4. data/.github/workflows/dummy.yml +9 -0
  5. data/.github/workflows/generator.yml +13 -0
  6. data/.github/workflows/node.yml +83 -0
  7. data/.github/workflows/ruby.yml +11 -0
  8. data/.github/workflows/test-bundlers.yml +10 -0
  9. data/CHANGELOG.md +24 -9
  10. data/CLAUDE.md +6 -10
  11. data/CONTRIBUTING.md +44 -0
  12. data/Gemfile.lock +1 -1
  13. data/README.md +74 -44
  14. data/docs/api-reference.md +519 -0
  15. data/docs/cdn_setup.md +3 -3
  16. data/docs/common-upgrades.md +6 -7
  17. data/docs/configuration.md +14 -8
  18. data/docs/css-modules-export-mode.md +40 -6
  19. data/docs/deployment.md +3 -3
  20. data/docs/early_hints_manual_api.md +1 -1
  21. data/docs/feature_testing.md +3 -3
  22. data/docs/optional-peer-dependencies.md +2 -2
  23. data/docs/precompile_hook.md +15 -15
  24. data/docs/react.md +1 -1
  25. data/docs/releasing.md +7 -7
  26. data/docs/rspack_migration_guide.md +8 -14
  27. data/docs/transpiler-migration.md +12 -9
  28. data/docs/troubleshooting.md +3 -3
  29. data/docs/using_swc_loader.md +13 -10
  30. data/docs/v6_upgrade.md +2 -2
  31. data/docs/v9_upgrade.md +78 -3
  32. data/eslint.config.fast.js +120 -8
  33. data/eslint.config.js +50 -31
  34. data/lib/install/config/shakapacker.yml +14 -1
  35. data/lib/shakapacker/bundler_switcher.rb +83 -18
  36. data/lib/shakapacker/configuration.rb +47 -4
  37. data/lib/shakapacker/dev_server_runner.rb +4 -0
  38. data/lib/shakapacker/doctor.rb +7 -7
  39. data/lib/shakapacker/runner.rb +1 -1
  40. data/lib/shakapacker/swc_migrator.rb +2 -2
  41. data/lib/shakapacker/version.rb +1 -1
  42. data/lib/tasks/shakapacker/binstubs.rake +4 -2
  43. data/lib/tasks/shakapacker/check_binstubs.rake +2 -2
  44. data/lib/tasks/shakapacker/doctor.rake +3 -3
  45. data/lib/tasks/shakapacker/export_bundler_config.rake +5 -9
  46. data/lib/tasks/shakapacker/install.rake +4 -2
  47. data/lib/tasks/shakapacker/switch_bundler.rake +30 -40
  48. data/package/config.ts +2 -3
  49. data/package/configExporter/cli.ts +29 -24
  50. data/package/dev_server.ts +2 -2
  51. data/package/env.ts +1 -1
  52. data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +6 -6
  53. data/package/environments/base.ts +2 -2
  54. data/package/environments/development.ts +3 -6
  55. data/package/environments/production.ts +2 -2
  56. data/package/environments/test.ts +2 -1
  57. data/package/esbuild/index.ts +0 -2
  58. data/package/index.d.ts +1 -0
  59. data/package/index.d.ts.template +1 -0
  60. data/package/index.ts +0 -1
  61. data/package/loaders.d.ts +1 -1
  62. data/package/plugins/rspack.ts +3 -1
  63. data/package/plugins/webpack.ts +5 -3
  64. data/package/rspack/index.ts +3 -3
  65. data/package/rules/file.ts +1 -1
  66. data/package/rules/raw.ts +3 -1
  67. data/package/rules/rspack.ts +0 -2
  68. data/package/rules/sass.ts +0 -2
  69. data/package/rules/webpack.ts +0 -1
  70. data/package/swc/index.ts +0 -2
  71. data/package/types.ts +8 -11
  72. data/package/utils/debug.ts +0 -4
  73. data/package/utils/getStyleRule.ts +17 -9
  74. data/package/utils/helpers.ts +8 -3
  75. data/package/utils/pathValidation.ts +10 -11
  76. data/package/utils/requireOrError.ts +4 -3
  77. data/package/webpack-types.d.ts +1 -1
  78. data/package/webpackDevServerConfig.ts +4 -4
  79. data/package.json +3 -3
  80. data/test/package/transpiler-defaults.test.js +42 -0
  81. data/yarn.lock +1 -1
  82. metadata +5 -2
@@ -150,11 +150,45 @@ If you prefer to keep the v8 default export behavior during migration, you can o
150
150
 
151
151
  ## Reverting to Default Exports (v8 Behavior)
152
152
 
153
- To use the v8-style default exports instead of v9's named exports:
153
+ To use the v8-style default exports instead of v9's named exports, you have several options:
154
154
 
155
- ### Option 1: Update `config/webpack/commonWebpackConfig.js` (Recommended)
155
+ ### Option 1: Configuration File (Easiest - Recommended)
156
156
 
157
- This approach modifies the common webpack configuration that applies to all environments:
157
+ The simplest way to restore v8 behavior is to set the `css_modules_export_mode` option in your `config/shakapacker.yml`:
158
+
159
+ ```yaml
160
+ # config/shakapacker.yml
161
+ default: &default
162
+ # ... other settings ...
163
+
164
+ # CSS Modules export mode
165
+ # named (default) - Use named exports with camelCase conversion (v9 default)
166
+ # default - Use default export with both original and camelCase names (v8 behavior)
167
+ css_modules_export_mode: default
168
+ ```
169
+
170
+ This configuration automatically adjusts the CSS loader settings:
171
+
172
+ - Sets `namedExport: false` to enable default exports
173
+ - Sets `exportLocalsConvention: 'camelCase'` to export both original and camelCase versions
174
+
175
+ **Restart your development server** after changing this setting for the changes to take effect.
176
+
177
+ With this configuration, you can continue using v8-style imports:
178
+
179
+ ```js
180
+ // Works with css_modules_export_mode: default
181
+ import styles from "./Component.module.css"
182
+ ;<div className={styles.container}>
183
+ <button className={styles.button}>Click me</button>
184
+ <button className={styles["my-button"]}>Kebab-case</button>
185
+ <button className={styles.myButton}>Also available</button>
186
+ </div>
187
+ ```
188
+
189
+ ### Option 2: Manual Webpack Configuration (Advanced)
190
+
191
+ If you need more control or can't use the configuration file approach, you can manually modify the webpack configuration that applies to all environments:
158
192
 
159
193
  ```js
160
194
  // config/webpack/commonWebpackConfig.js
@@ -198,7 +232,7 @@ const commonWebpackConfig = () => {
198
232
  module.exports = commonWebpackConfig
199
233
  ```
200
234
 
201
- ### Option 2: Create `config/webpack/environment.js` (Alternative)
235
+ ### Option 3: Create `config/webpack/environment.js` (Alternative)
202
236
 
203
237
  If you prefer using a separate environment file:
204
238
 
@@ -239,12 +273,12 @@ module.exports = environment
239
273
 
240
274
  Then reference this in your environment-specific configs (development.js, production.js, etc.).
241
275
 
242
- ### Option 3: (Optional) Sass Modules
276
+ ### Option 4: (Optional) Sass Modules
243
277
 
244
278
  If you also use Sass modules, add similar configuration for SCSS files:
245
279
 
246
280
  ```js
247
- // For Option 1 approach, extend the overrideCssModulesConfig function:
281
+ // For Option 2 approach (manual webpack config), extend the overrideCssModulesConfig function:
248
282
  const overrideCssModulesConfig = (config) => {
249
283
  // Handle both CSS and SCSS rules
250
284
  const styleRules = config.module.rules.filter(
data/docs/deployment.md CHANGED
@@ -16,7 +16,7 @@ Quick example for production deployment:
16
16
  ```yaml
17
17
  # config/shakapacker.yml
18
18
  production:
19
- precompile_hook: "bin/rails react_on_rails:generate_packs"
19
+ precompile_hook: "bin/rake react_on_rails:generate_packs"
20
20
  ```
21
21
 
22
22
  This ensures your dynamic entry points are generated before `assets:precompile` runs.
@@ -56,7 +56,7 @@ Your production build process is responsible for installing your JavaScript depe
56
56
  RAILS_ENV=staging bin/shakapacker
57
57
 
58
58
  # Also works with rake task
59
- RAILS_ENV=staging bundle exec rails assets:precompile
59
+ RAILS_ENV=staging bundle exec rake assets:precompile
60
60
  ```
61
61
 
62
62
  **How it works:**
@@ -156,7 +156,7 @@ Shakapacker supports serving JavaScript bundles and assets from a CDN. For a com
156
156
 
157
157
  ```bash
158
158
  export SHAKAPACKER_ASSET_HOST=https://cdn.example.com
159
- RAILS_ENV=production bundle exec rails assets:precompile
159
+ RAILS_ENV=production bundle exec rake assets:precompile
160
160
  ```
161
161
 
162
162
  Note: Shakapacker does NOT use the `ASSET_HOST` environment variable. You must use `SHAKAPACKER_ASSET_HOST` instead (`WEBPACKER_ASSET_HOST` if using Shakapacker before v7).
@@ -399,7 +399,7 @@ development: # or production
399
399
  bundle exec puma --early-hints
400
400
 
401
401
  # Option 2: Test in production mode locally (more realistic)
402
- RAILS_ENV=production rails assets:precompile # Compile assets first
402
+ RAILS_ENV=production bundle exec rake assets:precompile # Compile assets first
403
403
  RAILS_ENV=production bundle exec puma --early-hints -e production
404
404
  ```
405
405
 
@@ -434,7 +434,7 @@ curl http://localhost:3035/packs/application.js
434
434
 
435
435
  Use this checklist to verify a complete Shakapacker setup:
436
436
 
437
- - [ ] **Assets compile:** `bundle exec rails assets:precompile` succeeds
437
+ - [ ] **Assets compile:** `bundle exec rake assets:precompile` succeeds
438
438
  - [ ] **Manifest exists:** `public/packs/manifest.json` contains entrypoints
439
439
  - [ ] **Assets load:** Page loads without 404s for pack files
440
440
  - [ ] **Code splitting works:** Multiple chunks load in Network tab
@@ -456,7 +456,7 @@ cat public/packs/manifest.json | jq .
456
456
  **Recompile:**
457
457
 
458
458
  ```bash
459
- bundle exec rails assets:precompile
459
+ bundle exec rake assets:precompile
460
460
  ```
461
461
 
462
462
  ### Old Assets Cached
@@ -465,7 +465,7 @@ bundle exec rails assets:precompile
465
465
 
466
466
  ```bash
467
467
  rm -rf public/packs
468
- bundle exec rails assets:precompile
468
+ bundle exec rake assets:precompile
469
469
  ```
470
470
 
471
471
  ### Dev Server Won't Start
@@ -102,7 +102,7 @@ If upgrading from Shakapacker v8:
102
102
 
103
103
  ### New Installations
104
104
 
105
- The installer (`rails shakapacker:install`) only adds packages needed for your configuration:
105
+ The installer (`bundle exec rake shakapacker:install`) only adds packages needed for your configuration:
106
106
 
107
107
  - Detects your preferred bundler (webpack/rspack)
108
108
  - Installs appropriate JavaScript transpiler (babel/swc/esbuild)
@@ -159,7 +159,7 @@ The test suite includes:
159
159
 
160
160
  1. Check you've installed required dependencies for your configuration
161
161
  2. Refer to the configuration examples above
162
- 3. Run `rails shakapacker:doctor` for diagnostics
162
+ 3. Run `bundle exec rake shakapacker:doctor` for diagnostics
163
163
 
164
164
  ### TypeScript errors?
165
165
 
@@ -14,14 +14,14 @@ This is useful for:
14
14
 
15
15
  The precompile hook is especially useful when you need to run commands like:
16
16
 
17
- - `bin/rails react_on_rails:generate_packs` - Generate dynamic entry points
18
- - `bin/rails react_on_rails:locale` - Generate locale files
17
+ - `bin/rake react_on_rails:generate_packs` - Generate dynamic entry points
18
+ - `bin/rake react_on_rails:locale` - Generate locale files
19
19
  - Any custom script that prepares files before asset compilation
20
20
 
21
21
  **Important:** The hook runs in **both development and production**:
22
22
 
23
23
  - **Development**: Runs before `bin/shakapacker --watch` or dev server starts
24
- - **Production**: Runs before `rails assets:precompile`
24
+ - **Production**: Runs before `bundle exec rake assets:precompile`
25
25
 
26
26
  ## Configuration
27
27
 
@@ -39,7 +39,7 @@ development:
39
39
 
40
40
  production:
41
41
  <<: *default
42
- precompile_hook: "bin/rails react_on_rails:generate_packs"
42
+ precompile_hook: "rake react_on_rails:generate_packs"
43
43
  ```
44
44
 
45
45
  ## Creating a Precompile Hook Script
@@ -51,8 +51,8 @@ production:
51
51
  # bin/shakapacker-precompile-hook
52
52
 
53
53
  echo "Preparing assets..."
54
- bin/rails react_on_rails:generate_packs
55
- bin/rails react_on_rails:locale
54
+ bundle exec rake react_on_rails:generate_packs
55
+ bundle exec rake react_on_rails:locale
56
56
  echo "Assets prepared successfully"
57
57
  ```
58
58
 
@@ -117,14 +117,14 @@ For React on Rails projects, the hook replaces manual steps in your workflow:
117
117
 
118
118
  ```bash
119
119
  # Development
120
- bin/rails react_on_rails:generate_packs
121
- bin/rails react_on_rails:locale
120
+ bundle exec rake react_on_rails:generate_packs
121
+ bundle exec rake react_on_rails:locale
122
122
  bin/shakapacker-dev-server
123
123
 
124
124
  # Production
125
- bin/rails react_on_rails:generate_packs
126
- bin/rails react_on_rails:locale
127
- RAILS_ENV=production bin/rails assets:precompile
125
+ bundle exec rake react_on_rails:generate_packs
126
+ bundle exec rake react_on_rails:locale
127
+ RAILS_ENV=production rake assets:precompile
128
128
  ```
129
129
 
130
130
  ### After (Automatic)
@@ -138,8 +138,8 @@ default: &default
138
138
  ```bash
139
139
  #!/usr/bin/env bash
140
140
  # bin/react-on-rails-hook
141
- bin/rails react_on_rails:generate_packs
142
- bin/rails react_on_rails:locale
141
+ bundle exec rake react_on_rails:generate_packs
142
+ bundle exec rake react_on_rails:locale
143
143
  ```
144
144
 
145
145
  Now simply run:
@@ -149,7 +149,7 @@ Now simply run:
149
149
  bin/shakapacker-dev-server
150
150
 
151
151
  # Production
152
- RAILS_ENV=production bin/rails assets:precompile
152
+ RAILS_ENV=production bin/rake assets:precompile
153
153
  ```
154
154
 
155
155
  ## Security
@@ -292,7 +292,7 @@ default:
292
292
 
293
293
  if [ "$RAILS_ENV" = "production" ]; then
294
294
  echo "Running production-specific setup..."
295
- bin/rails react_on_rails:generate_packs
295
+ bin/rake react_on_rails:generate_packs
296
296
  else
297
297
  echo "Running development setup..."
298
298
  # Lighter-weight setup for development
data/docs/react.md CHANGED
@@ -132,7 +132,7 @@ rails new myapp --skip-javascript
132
132
  cd myapp
133
133
  bundle add shakapacker --strict
134
134
  ./bin/bundle install
135
- ./bin/rails shakapacker:install
135
+ bundle exec rake shakapacker:install
136
136
  npm install react react-dom @babel/preset-react
137
137
  npm install css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin
138
138
  ```
data/docs/releasing.md CHANGED
@@ -36,16 +36,16 @@ The automated release task handles the entire release process:
36
36
 
37
37
  ```bash
38
38
  # For a specific version (e.g., 9.1.0)
39
- rake create_release[9.1.0]
39
+ bundle exec rake create_release[9.1.0]
40
40
 
41
41
  # For a beta release (note: use period, not dash)
42
- rake create_release[9.2.0.beta.1] # Creates npm package 9.2.0-beta.1
42
+ bundle exec rake create_release[9.2.0.beta.1] # Creates npm package 9.2.0-beta.1
43
43
 
44
44
  # For a patch version bump (auto-increments)
45
- rake create_release
45
+ bundle exec rake create_release
46
46
 
47
47
  # Dry run to test without publishing
48
- rake create_release[9.1.0,true]
48
+ bundle exec rake create_release[9.1.0,true]
49
49
  ```
50
50
 
51
51
  ### 3. What the Release Task Does
@@ -83,13 +83,13 @@ The task automatically converts Ruby gem format to npm semver format:
83
83
 
84
84
  ```bash
85
85
  # Regular release
86
- rake create_release[9.1.0] # Gem: 9.1.0, npm: 9.1.0
86
+ bundle exec rake create_release[9.1.0] # Gem: 9.1.0, npm: 9.1.0
87
87
 
88
88
  # Beta release
89
- rake create_release[9.2.0.beta.1] # Gem: 9.2.0.beta.1, npm: 9.2.0-beta.1
89
+ bundle exec rake create_release[9.2.0.beta.1] # Gem: 9.2.0.beta.1, npm: 9.2.0-beta.1
90
90
 
91
91
  # Release candidate
92
- rake create_release[10.0.0.rc.1] # Gem: 10.0.0.rc.1, npm: 10.0.0-rc.1
92
+ bundle exec rake create_release[10.0.0.rc.1] # Gem: 10.0.0.rc.1, npm: 10.0.0-rc.1
93
93
  ```
94
94
 
95
95
  ### 5. During the Release
@@ -212,28 +212,22 @@ Shakapacker provides a convenient rake task to switch between webpack and rspack
212
212
 
213
213
  ```bash
214
214
  # Switch to rspack with automatic dependency management
215
- rails shakapacker:switch_bundler rspack --install-deps
216
- # or with rake (note the -- separator)
217
- rake shakapacker:switch_bundler rspack -- --install-deps
215
+ bin/rake shakapacker:switch_bundler rspack -- --install-deps
218
216
 
219
217
  # Fast switching without uninstalling old bundler (keeps both)
220
- rails shakapacker:switch_bundler webpack --install-deps --no-uninstall
221
- rake shakapacker:switch_bundler rspack -- --install-deps --no-uninstall
218
+ bin/rake shakapacker:switch_bundler rspack -- --install-deps --no-uninstall
222
219
 
223
220
  # Switch to rspack manually (you manage dependencies yourself)
224
- rails shakapacker:switch_bundler rspack
225
- rake shakapacker:switch_bundler rspack
221
+ bin/rake shakapacker:switch_bundler rspack
226
222
 
227
223
  # Switch back to webpack if needed
228
- rails shakapacker:switch_bundler webpack --install-deps
229
- rake shakapacker:switch_bundler webpack -- --install-deps
224
+ bin/rake shakapacker:switch_bundler webpack -- --install-deps
230
225
 
231
226
  # Show help
232
- rails shakapacker:switch_bundler --help
233
- rake shakapacker:switch_bundler -- --help
227
+ bin/rake shakapacker:switch_bundler -- --help
234
228
  ```
235
229
 
236
- **Note:** When using `rake`, you must use `--` to separate rake options from task arguments.
230
+ > **⚠️ Important:** This task must be run with `bin/rake`, not `bin/rails`.
237
231
 
238
232
  The task will:
239
233
 
@@ -246,7 +240,7 @@ The task will:
246
240
  **Custom Dependencies:** You can customize which dependencies are installed by creating a `.shakapacker-switch-bundler-dependencies.yml` file:
247
241
 
248
242
  ```bash
249
- rails shakapacker:switch_bundler --init-config
243
+ bundle exec rake shakapacker:switch_bundler --init-config
250
244
  ```
251
245
 
252
246
  ### Manual Migration Steps
@@ -840,7 +834,7 @@ To compare your webpack and rspack configurations during migration:
840
834
  bin/shakapacker-config --doctor
841
835
 
842
836
  # Switch to rspack
843
- rails shakapacker:switch_bundler rspack --install-deps
837
+ bundle exec rake shakapacker:switch_bundler rspack --install-deps
844
838
 
845
839
  # Export rspack configs to compare
846
840
  bin/shakapacker-config --doctor
@@ -4,10 +4,13 @@
4
4
 
5
5
  ## Default Transpilers
6
6
 
7
- Shakapacker uses different default JavaScript transpilers based on the bundler:
7
+ Shakapacker v9 transpiler defaults depend on the bundler and installation:
8
8
 
9
- - **Webpack**: `babel` (default) - Maintains backward compatibility
10
- - **Rspack**: `swc` (default) - Modern, faster transpiler for new bundler
9
+ - **New installations (v9+)**: `swc` - Installation template explicitly sets SWC (20x faster than Babel)
10
+ - **Webpack runtime default**: `babel` - Used when no explicit config is provided (maintains backward compatibility)
11
+ - **Rspack runtime default**: `swc` - Rspack defaults to SWC as it's a newer bundler with modern defaults
12
+
13
+ **Key distinction**: The installation template (`lib/install/config/shakapacker.yml`) explicitly sets `javascript_transpiler: "swc"` for new projects, but if you're upgrading or have no explicit config, webpack falls back to Babel for backward compatibility.
11
14
 
12
15
  ## Available Transpilers
13
16
 
@@ -22,15 +25,15 @@ Set the transpiler in your `config/shakapacker.yml`:
22
25
 
23
26
  ```yaml
24
27
  default: &default
25
- # For webpack users (babel is default, no change needed)
26
- javascript_transpiler: babel
27
-
28
- # To opt-in to SWC for better performance
28
+ # SWC is the default (recommended - 20x faster than Babel)
29
29
  javascript_transpiler: swc
30
30
 
31
- # For rspack users (swc is default, no change needed)
31
+ # To use Babel for backward compatibility
32
+ javascript_transpiler: babel
33
+
34
+ # For rspack users (defaults to swc if not specified)
32
35
  assets_bundler: rspack
33
- javascript_transpiler: swc
36
+ # javascript_transpiler can be set, but rspack defaults to swc
34
37
  ```
35
38
 
36
39
  ## Migration Guide
@@ -280,7 +280,7 @@ See the [deployment guide](./deployment.md#custom-rails-environments-eg-staging)
280
280
  ## ENOENT: no such file or directory - node-sass
281
281
 
282
282
  If you get the error `ENOENT: no such file or directory - node-sass` on deploy with
283
- `assets:precompile` or `bundle exec rails shakapacker:compile` you may need to
283
+ `assets:precompile` or `bundle exec rake shakapacker:compile` you may need to
284
284
  move Sass to production `dependencies`.
285
285
 
286
286
  Move any packages that related to Sass (e.g. `node-sass` or `sass-loader`) from
@@ -326,13 +326,13 @@ In `package.json`:
326
326
 
327
327
  ## webpack or webpack-dev-server not found
328
328
 
329
- - This could happen if `shakapacker:install` step is skipped. Please run `bundle exec rails shakapacker:install` to fix the issue.
329
+ - This could happen if `shakapacker:install` step is skipped. Please run `bundle exec rake shakapacker:install` to fix the issue.
330
330
 
331
331
  - If you encounter the above error on heroku after upgrading from Rails 4.x to 5.1.x, then the problem might be related to missing `yarn` binstub. Please run following commands to update/add binstubs:
332
332
 
333
333
  ```bash
334
334
  bundle config --delete bin
335
- ./bin/rails app:update:bin # or rails app:update:bin
335
+ bundle exec rake app:update:bin
336
336
  ```
337
337
 
338
338
  ## Running webpack on Windows
@@ -1,8 +1,6 @@
1
1
  # Using SWC Loader
2
2
 
3
- :warning: This feature is currently experimental. The configuration and API are subject to change during the beta release cycle.
4
-
5
- If you face any issues, please report at https://github.com/shakacode/shakapacker/issues.
3
+ SWC is the recommended JavaScript transpiler in Shakapacker v9+, and is set as the default in new installations. If you face any issues, please report them at [Shakapacker Issues](https://github.com/shakacode/shakapacker/issues).
6
4
 
7
5
  ## About SWC
8
6
 
@@ -12,20 +10,23 @@ It supports all ECMAScript features and it's designed to be a drop-in replacemen
12
10
 
13
11
  For comparison between SWC and Babel, see the docs at https://swc.rs/docs/migrating-from-babel.
14
12
 
15
- > **Note:** SWC is also natively built into RSpack bundler, providing even faster compilation speeds. When using RSpack (`assets_bundler: 'rspack'`), SWC is used automatically regardless of the `javascript_transpiler` setting.
13
+ > **Note:** SWC is also natively built into RSpack bundler, providing even faster compilation speeds. When using RSpack (`assets_bundler: 'rspack'`), SWC is the default if `javascript_transpiler` is not explicitly set.
14
+
15
+ ## Using SWC in your Shakapacker project
16
16
 
17
- ## Switching your Shakapacker project to SWC
17
+ For new installations of Shakapacker v9+, SWC is automatically configured in the installation template.
18
18
 
19
- In order to use SWC as your compiler today. You need to do two things:
19
+ **Note**: While the installation template sets SWC as the default, webpack's runtime fallback (when no explicit config exists) remains Babel for backward compatibility. Rspack always defaults to SWC.
20
+
21
+ If you're upgrading from v8 or earlier and want to switch from Babel to SWC:
20
22
 
21
23
  1. Make sure you've installed `@swc/core` and `swc-loader` packages.
22
24
 
23
- ```
25
+ ```bash
24
26
  npm install @swc/core swc-loader
25
27
  ```
26
28
 
27
- 2. Add or change `javascript_transpiler` value in your default `shakapacker.yml` config to `swc`
28
- The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
29
+ 2. Confirm `javascript_transpiler` is set to `swc` in your `config/shakapacker.yml`:
29
30
 
30
31
  ```yml
31
32
  default: &default
@@ -43,7 +44,9 @@ default: &default
43
44
  # Reload manifest.json on all requests so we reload latest compiled packs
44
45
  cache_manifest: false
45
46
 
46
- # Select JavaScript transpiler to use, available options are 'babel' (default) or 'swc'
47
+ # Select JavaScript transpiler to use
48
+ # Available options: 'swc' (default, 20x faster), 'babel', or 'esbuild'
49
+ # Note: When using rspack, swc is used automatically regardless of this setting
47
50
  javascript_transpiler: "swc"
48
51
  ```
49
52
 
data/docs/v6_upgrade.md CHANGED
@@ -80,7 +80,7 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
80
80
  ```
81
81
 
82
82
  ```bash
83
- bundle exec rails webpacker:install
83
+ bundle exec rake webpacker:install
84
84
  ```
85
85
 
86
86
  Overwrite all files and check what changed.
@@ -181,7 +181,7 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
181
181
 
182
182
  1. Make sure that you can run `bin/webpack` without errors.
183
183
 
184
- 1. Try running `RAILS_ENV=production bin/rails assets:precompile`. If all goes well, don't forget to clean the generated assets with `bin/rails assets:clobber`.
184
+ 1. Try running `RAILS_ENV=production rake assets:precompile`. If all goes well, don't forget to clean the generated assets with `rake assets:clobber`.
185
185
 
186
186
  1. Run `yarn add webpack-dev-server` if those are not already in your dev dependencies. Make sure you're using v4+.
187
187
 
data/docs/v9_upgrade.md CHANGED
@@ -145,9 +145,84 @@ import * as styles from './Component.module.css';
145
145
  - TypeScript: Change to namespace imports (`import * as styles`)
146
146
  - Kebab-case class names are automatically converted to camelCase
147
147
 
148
- 2. **Keep v8 behavior** temporarily:
149
- - Override the css-loader configuration as shown in [CSS Modules Export Mode documentation](./css-modules-export-mode.md)
150
- - This gives you time to migrate gradually
148
+ 2. **Keep v8 behavior** temporarily using configuration file (Easiest):
149
+
150
+ ```yaml
151
+ # config/shakapacker.yml
152
+ css_modules_export_mode: default
153
+ ```
154
+
155
+ This allows you to keep using default imports while migrating gradually
156
+
157
+ 3. **Keep v8 behavior** using webpack configuration (Advanced):
158
+
159
+ If you need more control over the configuration, you can override the css-loader settings directly in your webpack config.
160
+
161
+ **Where to add this:** Create or modify `config/webpack/webpack.config.js`. If this file doesn't exist, create it and ensure your `config/webpacker.yml` or build process loads it. See [Webpack Configuration](./webpack.md) for details on customizing webpack.
162
+
163
+ ```javascript
164
+ // config/webpack/webpack.config.js
165
+ const { generateWebpackConfig, merge } = require("shakapacker")
166
+
167
+ const customConfig = () => {
168
+ const config = merge({}, generateWebpackConfig())
169
+
170
+ // Override CSS Modules to use default exports (v8 behavior)
171
+ config.module.rules.forEach((rule) => {
172
+ if (
173
+ rule.test &&
174
+ (rule.test.test("example.module.scss") ||
175
+ rule.test.test("example.module.css"))
176
+ ) {
177
+ if (Array.isArray(rule.use)) {
178
+ rule.use.forEach((loader) => {
179
+ if (
180
+ loader.loader &&
181
+ loader.loader.includes("css-loader") &&
182
+ loader.options &&
183
+ loader.options.modules
184
+ ) {
185
+ // Disable named exports to support default imports
186
+ loader.options.modules.namedExport = false
187
+ loader.options.modules.exportLocalsConvention = "camelCase"
188
+ }
189
+ })
190
+ }
191
+ }
192
+ })
193
+
194
+ return config
195
+ }
196
+
197
+ module.exports = customConfig
198
+ ```
199
+
200
+ **Key points:**
201
+ - Test both `.module.scss` and `.module.css` file extensions
202
+ - Validate all loader properties exist before accessing them
203
+ - Use `.includes('css-loader')` since the loader path may vary
204
+ - Set both `namedExport: false` and `exportLocalsConvention: 'camelCase'` for full v8 compatibility
205
+
206
+ **Debugging tip:** To verify the override is applied correctly, you can inspect the webpack config:
207
+
208
+ ```javascript
209
+ // Add this temporarily to verify your changes
210
+ if (process.env.DEBUG_WEBPACK_CONFIG) {
211
+ const cssModuleRules = config.module.rules
212
+ .filter((r) => r.test?.test?.("example.module.css"))
213
+ .flatMap((r) => r.use?.filter((l) => l.loader?.includes("css-loader")))
214
+ console.log(
215
+ "CSS Module loader options:",
216
+ JSON.stringify(cssModuleRules, null, 2)
217
+ )
218
+ }
219
+ ```
220
+
221
+ Then run: `DEBUG_WEBPACK_CONFIG=true bin/shakapacker`
222
+
223
+ **Note:** This is a temporary solution. The recommended approach is to migrate your imports to use named exports as shown in the main documentation.
224
+
225
+ For detailed configuration options, see the [CSS Modules Export Mode documentation](./css-modules-export-mode.md)
151
226
 
152
227
  **Benefits of the change:**
153
228