shakapacker 9.3.0.beta.7 → 9.3.1

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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/update-changelog.md +224 -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 +55 -111
  10. data/CLAUDE.md +6 -10
  11. data/CONTRIBUTING.md +57 -0
  12. data/Gemfile.lock +1 -1
  13. data/README.md +84 -8
  14. data/docs/api-reference.md +519 -0
  15. data/docs/configuration.md +38 -4
  16. data/docs/css-modules-export-mode.md +40 -6
  17. data/docs/rspack_migration_guide.md +238 -2
  18. data/docs/transpiler-migration.md +12 -9
  19. data/docs/troubleshooting.md +21 -21
  20. data/docs/using_swc_loader.md +13 -10
  21. data/docs/v9_upgrade.md +11 -2
  22. data/eslint.config.fast.js +128 -8
  23. data/eslint.config.js +89 -33
  24. data/knip.ts +8 -1
  25. data/lib/install/config/shakapacker.yml +20 -7
  26. data/lib/shakapacker/configuration.rb +274 -8
  27. data/lib/shakapacker/dev_server.rb +88 -1
  28. data/lib/shakapacker/dev_server_runner.rb +4 -0
  29. data/lib/shakapacker/doctor.rb +5 -5
  30. data/lib/shakapacker/instance.rb +85 -1
  31. data/lib/shakapacker/manifest.rb +85 -11
  32. data/lib/shakapacker/version.rb +1 -1
  33. data/lib/shakapacker.rb +143 -3
  34. data/lib/tasks/shakapacker/doctor.rake +1 -1
  35. data/lib/tasks/shakapacker/export_bundler_config.rake +4 -4
  36. data/package/config.ts +2 -4
  37. data/package/configExporter/buildValidator.ts +53 -29
  38. data/package/configExporter/cli.ts +106 -76
  39. data/package/configExporter/configFile.ts +33 -26
  40. data/package/configExporter/types.ts +64 -0
  41. data/package/configExporter/yamlSerializer.ts +118 -43
  42. data/package/dev_server.ts +3 -2
  43. data/package/env.ts +2 -2
  44. data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +6 -6
  45. data/package/environments/base.ts +6 -6
  46. data/package/environments/development.ts +7 -9
  47. data/package/environments/production.ts +7 -8
  48. data/package/environments/test.ts +4 -2
  49. data/package/esbuild/index.ts +0 -2
  50. data/package/index.d.ts +1 -0
  51. data/package/index.d.ts.template +1 -0
  52. data/package/index.ts +28 -5
  53. data/package/loaders.d.ts +2 -2
  54. data/package/optimization/webpack.ts +29 -31
  55. data/package/plugins/rspack.ts +3 -1
  56. data/package/plugins/webpack.ts +5 -3
  57. data/package/rspack/index.ts +5 -4
  58. data/package/rules/file.ts +2 -1
  59. data/package/rules/jscommon.ts +1 -0
  60. data/package/rules/raw.ts +3 -1
  61. data/package/rules/rspack.ts +0 -2
  62. data/package/rules/sass.ts +0 -2
  63. data/package/rules/webpack.ts +0 -1
  64. data/package/swc/index.ts +0 -2
  65. data/package/types.ts +8 -11
  66. data/package/utils/debug.ts +0 -4
  67. data/package/utils/getStyleRule.ts +17 -9
  68. data/package/utils/helpers.ts +8 -4
  69. data/package/utils/pathValidation.ts +78 -18
  70. data/package/utils/requireOrError.ts +14 -5
  71. data/package/utils/typeGuards.ts +43 -46
  72. data/package/webpack-types.d.ts +2 -2
  73. data/package/webpackDevServerConfig.ts +5 -4
  74. data/package.json +2 -3
  75. data/test/package/configExporter/cli.test.js +440 -0
  76. data/test/package/configExporter/types.test.js +163 -0
  77. data/test/package/configExporter.test.js +264 -0
  78. data/test/package/transpiler-defaults.test.js +42 -0
  79. data/test/package/yamlSerializer.test.js +204 -0
  80. data/test/typescript/pathValidation.test.js +44 -0
  81. data/test/typescript/requireOrError.test.js +49 -0
  82. data/yarn.lock +0 -32
  83. metadata +14 -5
  84. data/.eslintrc.fast.js +0 -40
  85. data/.eslintrc.js +0 -84
@@ -11,7 +11,9 @@
11
11
  - [Server-Side Rendering (SSR) Considerations](#server-side-rendering-ssr-considerations)
12
12
  - [Key Differences from Webpack](#key-differences-from-webpack)
13
13
  - [Migration Steps](#migration-steps)
14
+ - [Build Verification](#build-verification)
14
15
  - [Configuration Best Practices](#configuration-best-practices)
16
+ - [Common Migration Issues](#common-migration-issues)
15
17
  - [Common Issues and Solutions](#common-issues-and-solutions)
16
18
  - [Performance Tips](#performance-tips)
17
19
  - [Debugging Configuration](#debugging-configuration)
@@ -312,6 +314,73 @@ bin/shakapacker --mode production
312
314
  - [ ] Deploy to staging
313
315
  - [ ] Monitor performance improvements
314
316
 
317
+ ## Build Verification
318
+
319
+ After completing your migration, verify that everything works correctly:
320
+
321
+ ### Basic Build Verification
322
+
323
+ ```bash
324
+ # Clean previous build artifacts
325
+ rm -rf public/packs public/packs-test
326
+
327
+ # Test development build
328
+ bin/shakapacker
329
+
330
+ # Test production build
331
+ RAILS_ENV=production bin/shakapacker
332
+
333
+ # Verify assets were generated
334
+ ls -la public/packs/
335
+ ```
336
+
337
+ ### SSR Build Verification
338
+
339
+ If your application uses Server-Side Rendering, perform these additional checks:
340
+
341
+ ```bash
342
+ # 1. Verify server bundle was created
343
+ ls -la public/packs/*-server-bundle.js
344
+
345
+ # 2. Test SSR rendering in Rails console
346
+ bundle exec rails console
347
+ # In console:
348
+ ReactOnRails::ServerRenderingPool.reset_pool
349
+ # Then visit a page that uses SSR and check for errors
350
+
351
+ # 3. Run full test suite (watch for SSR-related failures)
352
+ bundle exec rspec
353
+
354
+ # 4. Check for CSS extraction issues in SSR
355
+ # Look for "Cannot read properties of undefined" errors in tests
356
+ # or intermittent test failures related to styling
357
+ ```
358
+
359
+ ### Common Verification Issues
360
+
361
+ **Silent SSR failures**: If your SSR pages render without errors but components appear unstyled or with missing data, check:
362
+
363
+ - Server bundle is being generated correctly
364
+ - CSS extraction is disabled for server bundle (see [Common Migration Issues](#common-migration-issues))
365
+ - React runtime configuration is compatible with your SSR framework
366
+
367
+ **Error patterns to watch for**:
368
+
369
+ - `Cannot read properties of undefined (reading 'className')` - CSS Modules configuration issue
370
+ - `Invalid call to renderToString` - React runtime compatibility issue
371
+ - `Module not found: Can't resolve './Module.bs.js'` - File extension resolution issue
372
+ - Intermittent/flaky tests - CSS extraction leaking into server bundle
373
+
374
+ ### Testing Strategy for SSR
375
+
376
+ For applications with SSR, follow this verification order:
377
+
378
+ 1. Test client-only pages first (verify basic Rspack build works)
379
+ 2. Test SSR pages without CSS modules (verify SSR configuration)
380
+ 3. Test SSR pages with CSS modules (verify CSS extraction + SSR work together)
381
+ 4. Run full test suite multiple times to catch flaky tests
382
+ 5. Test in production mode (some issues only appear with minification)
383
+
315
384
  ## Configuration Best Practices
316
385
 
317
386
  ### Configuration Organization
@@ -390,6 +459,173 @@ When upgrading to Shakapacker 9 with Rspack:
390
459
  4. **Check Node version compatibility**: Verify your Node version meets all dependency requirements
391
460
  5. **Don't make empty commits**: If CI fails but local passes, investigate the root cause - don't try to "trigger CI re-run" with empty commits
392
461
 
462
+ ## Common Migration Issues
463
+
464
+ This section highlights the most critical configuration issues that cause build failures during webpack-to-Rspack migration. These issues are especially important for applications using Server-Side Rendering (SSR), CSS Modules, or non-standard file extensions.
465
+
466
+ ### 1. SWC React Runtime for SSR (CRITICAL for React on Rails)
467
+
468
+ **Problem**: React on Rails SSR detection expects specific function signatures that may not work with SWC's automatic React runtime.
469
+
470
+ **Symptoms**:
471
+
472
+ - Error: `Invalid call to renderToString. Possibly you have a renderFunction...`
473
+ - SSR pages fail to render or render without React hydration
474
+
475
+ **Solution**: Configure SWC to use classic React runtime instead of automatic:
476
+
477
+ ```javascript
478
+ // config/swc.config.js
479
+ const customConfig = {
480
+ options: {
481
+ jsc: {
482
+ transform: {
483
+ react: {
484
+ runtime: "classic", // Use 'classic' instead of 'automatic' for SSR
485
+ refresh: env.isDevelopment && env.runningWebpackDevServer
486
+ }
487
+ }
488
+ }
489
+ }
490
+ }
491
+ ```
492
+
493
+ **Why this matters**: The automatic runtime changes how React imports work (`import { jsx as _jsx }` vs `import React`), which breaks React on Rails' SSR function detection logic. This is a silent failure that only manifests at runtime.
494
+
495
+ **Implementation checklist for SSR users**:
496
+
497
+ - [ ] Locate your SWC configuration file (typically `config/swc.config.js`)
498
+ - [ ] Change `runtime: 'automatic'` to `runtime: 'classic'`
499
+ - [ ] Test SSR rendering in development and production modes
500
+ - [ ] Verify React hydration works correctly on client side
501
+ - [ ] Run full test suite to catch any related issues
502
+
503
+ ### 2. CSS Modules Configuration for Server Bundles (CRITICAL for SSR + CSS Modules)
504
+
505
+ **Problem**: When configuring server bundles, you must preserve Shakapacker 9's CSS Modules settings (`namedExport: true`) while adding SSR-specific settings. Simply setting `exportOnlyLocals: true` will override the base configuration and break CSS imports.
506
+
507
+ **Symptoms**:
508
+
509
+ - Error: `export 'default' (imported as 'css') was not found`
510
+ - CSS classes return undefined in SSR
511
+ - Client-side CSS works but SSR fails
512
+ - Intermittent/flaky test failures
513
+
514
+ **Solution**: Use spread operator to merge CSS Modules options instead of replacing them:
515
+
516
+ ```javascript
517
+ // config/webpack/serverWebpackConfig.js
518
+ if (cssLoader && cssLoader.options && cssLoader.options.modules) {
519
+ // ✅ CORRECT - Preserves namedExport and other settings
520
+ cssLoader.options.modules = {
521
+ ...cssLoader.options.modules,
522
+ exportOnlyLocals: true
523
+ }
524
+
525
+ // ❌ INCORRECT - Overwrites all settings
526
+ // cssLoader.options.modules.exportOnlyLocals = true
527
+ }
528
+ ```
529
+
530
+ **Why this matters**: Shakapacker 9 changed the default CSS Modules configuration to use named exports. If you only set `exportOnlyLocals: true` without preserving the base config, you'll lose the `namedExport: true` setting, causing import/export mismatches between client and server bundles.
531
+
532
+ **Related configuration**: You must also filter out CSS extraction loaders in server bundles:
533
+
534
+ ```javascript
535
+ // config/webpack/serverWebpackConfig.js
536
+ rule.use = rule.use.filter((item) => {
537
+ let testValue
538
+ if (typeof item === "string") {
539
+ testValue = item
540
+ } else if (typeof item.loader === "string") {
541
+ testValue = item.loader
542
+ }
543
+ // Handle both Webpack and Rspack CSS extract loaders
544
+ return !(
545
+ testValue?.match(/mini-css-extract-plugin/) ||
546
+ testValue?.includes("cssExtractLoader") || // Rspack uses this path
547
+ testValue === "style-loader"
548
+ )
549
+ })
550
+ ```
551
+
552
+ **Implementation checklist for SSR + CSS Modules users**:
553
+
554
+ - [ ] Update server bundle config to use spread operator for CSS Modules options
555
+ - [ ] Ensure CSS extraction loaders are filtered for both webpack and Rspack paths
556
+ - [ ] Test SSR pages with CSS Modules imports
557
+ - [ ] Verify CSS classes are defined (not undefined) during SSR
558
+ - [ ] Run tests multiple times to catch flaky failures
559
+
560
+ ### 3. ReScript File Resolution (CRITICAL for ReScript users)
561
+
562
+ **Problem**: Rspack requires explicit configuration to resolve `.bs.js` extensions (ReScript compiled output), while webpack handled this automatically.
563
+
564
+ **Symptoms**:
565
+
566
+ - Error: `Module not found: Can't resolve './Module.bs.js'`
567
+ - ReScript modules fail to import
568
+ - Build fails with missing module errors
569
+
570
+ **Solution**: Add `.bs.js` to resolve extensions:
571
+
572
+ ```javascript
573
+ // config/webpack/webpack.config.js (works for both webpack and rspack)
574
+ const commonOptions = {
575
+ resolve: {
576
+ extensions: [".css", ".ts", ".tsx", ".bs.js"] // Add .bs.js for ReScript
577
+ }
578
+ }
579
+
580
+ module.exports = merge({}, baseConfig, commonOptions)
581
+ ```
582
+
583
+ **Why this matters**: ReScript compiles `.res` source files to `.bs.js` JavaScript files. If your bundler can't resolve these extensions, all ReScript imports will fail, even though the compiled files exist.
584
+
585
+ **Additional consideration - Missing compiled files**: Some ReScript npm packages ship only `.res` source files without compiled `.bs.js` files. If you encounter this, use `patch-package` to fix the dependency's `bsconfig.json` (see detailed solution in [Common Issues and Solutions](#issue-rescript-dependencies-missing-compiled-files)).
586
+
587
+ **Implementation checklist for ReScript users**:
588
+
589
+ - [ ] Add `.bs.js` to resolve extensions in webpack/rspack config
590
+ - [ ] Verify all ReScript modules can be imported
591
+ - [ ] Check if any ReScript dependencies are missing compiled files
592
+ - [ ] If needed, patch broken dependencies with `patch-package`
593
+ - [ ] Test build with all ReScript code paths
594
+
595
+ ### 4. Build Verification Steps (IMPORTANT for all migrations)
596
+
597
+ **Problem**: The migration documentation lacked practical verification procedures, leaving developers without guidance on testing SSR functionality or identifying configuration errors.
598
+
599
+ **Solution**: Follow the comprehensive verification steps in the [Build Verification](#build-verification) section above, which includes:
600
+
601
+ - Basic build verification commands
602
+ - SSR-specific testing procedures
603
+ - Error pattern identification
604
+ - Testing strategy for SSR applications
605
+
606
+ **Why this matters**: Silent SSR failures and configuration issues often only manifest in specific scenarios (production mode, certain page types, race conditions in tests). Without systematic verification, these issues may slip into production.
607
+
608
+ **Implementation checklist for all users**:
609
+
610
+ - [ ] Clean build artifacts before testing
611
+ - [ ] Test both development and production builds
612
+ - [ ] Verify generated assets in `public/packs/`
613
+ - [ ] For SSR: verify server bundle generation
614
+ - [ ] For SSR: test rendering in Rails console
615
+ - [ ] Run full test suite multiple times
616
+ - [ ] Check for error patterns listed in Build Verification
617
+
618
+ ### Configuration Differences: webpack vs Rspack Summary
619
+
620
+ Quick reference for the key differences that cause migration issues:
621
+
622
+ | Area | Webpack | Rspack | Migration Action |
623
+ | -------------------------- | ------------------------- | ----------------------------------- | ------------------------------------------- |
624
+ | CSS Extraction Loader Path | `mini-css-extract-plugin` | `cssExtractLoader.js` | Filter both paths in SSR config |
625
+ | React Runtime (SSR) | Works with both | Classic required for React on Rails | Use `runtime: 'classic'` |
626
+ | ReScript Extensions | Auto-resolves `.bs.js` | Requires explicit config | Add to `resolve.extensions` |
627
+ | CSS Modules Default | `namedExport: true` (v9+) | Same | Preserve with spread operator in SSR config |
628
+
393
629
  ## Common Issues and Solutions
394
630
 
395
631
  ### Issue: CSS Modules Returning Undefined (CRITICAL)
@@ -601,13 +837,13 @@ To compare your webpack and rspack configurations during migration:
601
837
 
602
838
  ```bash
603
839
  # Export webpack configs before switching
604
- bin/export-bundler-config --doctor
840
+ bin/shakapacker-config --doctor
605
841
 
606
842
  # Switch to rspack
607
843
  rails shakapacker:switch_bundler rspack --install-deps
608
844
 
609
845
  # Export rspack configs to compare
610
- bin/export-bundler-config --doctor
846
+ bin/shakapacker-config --doctor
611
847
 
612
848
  # Compare the files in shakapacker-config-exports/
613
849
  diff shakapacker-config-exports/webpack-production-client.yaml \
@@ -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
@@ -21,7 +21,7 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
21
21
 
22
22
  4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-shakapacker`
23
23
 
24
- 5. **Export your full webpack/rspack configuration for analysis**: Use the `bin/export-bundler-config` utility to export your complete resolved configuration. This is especially helpful for:
24
+ 5. **Export your full webpack/rspack configuration for analysis**: Use the `bin/shakapacker-config` utility to export your complete resolved configuration. This is especially helpful for:
25
25
  - **Migrations**: Comparing configurations before and after migrating between webpack and rspack, or between different Shakapacker versions
26
26
  - **Debugging**: Inspecting the exact configuration webpack/rspack is using, including all merged settings
27
27
  - **AI Analysis**: Uploading the exported config to ChatGPT or other AI tools for troubleshooting
@@ -35,7 +35,7 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
35
35
  rake shakapacker:binstubs
36
36
 
37
37
  # Export EVERYTHING for troubleshooting (dev + prod, annotated YAML)
38
- bin/export-bundler-config --doctor
38
+ bin/shakapacker-config --doctor
39
39
  # Creates: webpack-development-client.yaml, webpack-development-server.yaml,
40
40
  # webpack-production-client.yaml, webpack-production-server.yaml
41
41
  ```
@@ -44,28 +44,28 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
44
44
 
45
45
  ```bash
46
46
  # Save current environment configs with auto-generated names
47
- bin/export-bundler-config --save
47
+ bin/shakapacker-config --save
48
48
  # Creates: webpack-development-client.yaml, webpack-development-server.yaml
49
49
 
50
50
  # Save to specific directory
51
- bin/export-bundler-config --save --save-dir=./debug-configs
51
+ bin/shakapacker-config --save --save-dir=./debug-configs
52
52
 
53
53
  # Export only client config for production
54
- bin/export-bundler-config --save --env=production --client-only
54
+ bin/shakapacker-config --save --env=production --client-only
55
55
  # Creates: webpack-production-client.yaml
56
56
 
57
57
  # Compare development vs production configs
58
- bin/export-bundler-config --save --save-dir=./configs
58
+ bin/shakapacker-config --save --save-dir=./configs
59
59
  diff configs/webpack-development-client.yaml configs/webpack-production-client.yaml
60
60
 
61
61
  # View config in terminal (no files created)
62
- bin/export-bundler-config
62
+ bin/shakapacker-config
63
63
 
64
64
  # Export without inline documentation annotations
65
- bin/export-bundler-config --save --no-annotate
65
+ bin/shakapacker-config --save --no-annotate
66
66
 
67
67
  # Export in JSON format for programmatic analysis
68
- bin/export-bundler-config --save --format=json
68
+ bin/shakapacker-config --save --format=json
69
69
  ```
70
70
 
71
71
  **Config files are automatically named:** `{bundler}-{env}-{type}.{ext}`
@@ -73,9 +73,9 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
73
73
  - YAML format includes inline documentation explaining each config key
74
74
  - Separate files for client and server bundles (cleaner than combined)
75
75
 
76
- See `bin/export-bundler-config --help` for all available options.
76
+ See `bin/shakapacker-config --help` for all available options.
77
77
 
78
- 6. **Validate your webpack/rspack builds**: Use `bin/export-bundler-config --validate` to test that all your build configurations compile successfully. This is especially useful for:
78
+ 6. **Validate your webpack/rspack builds**: Use `bin/shakapacker-config --validate` to test that all your build configurations compile successfully. This is especially useful for:
79
79
  - **CI/CD pipelines**: Catch configuration errors before deployment
80
80
  - **Migration testing**: Verify builds work after upgrading webpack, rspack, or Shakapacker
81
81
  - **Multi-environment testing**: Ensure all build configurations (dev, prod, HMR) compile correctly
@@ -84,13 +84,13 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
84
84
 
85
85
  ```bash
86
86
  # Validate all builds defined in .bundler-config.yml
87
- bin/export-bundler-config --validate
87
+ bin/shakapacker-config --validate
88
88
 
89
89
  # Validate with full output logs (shows all webpack/rspack compilation output)
90
- bin/export-bundler-config --validate --verbose
90
+ bin/shakapacker-config --validate --verbose
91
91
 
92
92
  # Validate a specific build
93
- bin/export-bundler-config --validate-build=dev-hmr
93
+ bin/shakapacker-config --validate-build=dev-hmr
94
94
  ```
95
95
 
96
96
  **Verbose Mode:**
@@ -108,13 +108,13 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
108
108
 
109
109
  ```bash
110
110
  # Create a .bundler-config.yml file with example builds
111
- bin/export-bundler-config --init
111
+ bin/shakapacker-config --init
112
112
 
113
113
  # List all available builds
114
- bin/export-bundler-config --list-builds
114
+ bin/shakapacker-config --list-builds
115
115
 
116
116
  # Validate all builds
117
- bin/export-bundler-config --validate
117
+ bin/shakapacker-config --validate
118
118
  ```
119
119
 
120
120
  **Advanced options:**
@@ -177,9 +177,9 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
177
177
  💡 Debugging Tips:
178
178
  To get more details, run individual builds with --verbose:
179
179
 
180
- bin/export-bundler-config --validate-build prod --verbose
180
+ bin/shakapacker-config --validate-build prod --verbose
181
181
 
182
- Or validate all builds with full output: bin/export-bundler-config --validate --verbose
182
+ Or validate all builds with full output: bin/shakapacker-config --validate --verbose
183
183
  ================================================================================
184
184
  ```
185
185
 
@@ -189,13 +189,13 @@ If you're experiencing FOUC where content briefly appears unstyled before CSS lo
189
189
  1. **Run a specific build with verbose output** to see full webpack/rspack logs:
190
190
 
191
191
  ```bash
192
- bin/export-bundler-config --validate-build prod --verbose
192
+ bin/shakapacker-config --validate-build prod --verbose
193
193
  ```
194
194
 
195
195
  2. **Validate all builds with verbose output** to see everything:
196
196
 
197
197
  ```bash
198
- bin/export-bundler-config --validate --verbose
198
+ bin/shakapacker-config --validate --verbose
199
199
  ```
200
200
 
201
201
  3. **Test individual builds manually** using the same configuration:
@@ -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/v9_upgrade.md CHANGED
@@ -145,9 +145,18 @@ 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:
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):
149
158
  - 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
159
+ - Provides more control over the configuration
151
160
 
152
161
  **Benefits of the change:**
153
162
 
@@ -17,14 +17,23 @@ module.exports = [
17
17
  // Global ignores (replaces .eslintignore)
18
18
  {
19
19
  ignores: [
20
- "lib/**",
21
- "**/node_modules/**",
22
- "vendor/**",
23
- "spec/**",
24
- "package/**" // TODO: Remove after issue #644 is resolved (lints package/ TS source files)
20
+ "lib/**", // Ruby files, not JavaScript
21
+ "**/node_modules/**", // Third-party dependencies
22
+ "vendor/**", // Vendored dependencies
23
+ "spec/**", // Ruby specs, not JavaScript
24
+ "package/**/*.js", // Generated/compiled JavaScript from TypeScript
25
+ "package/**/*.d.ts" // Generated TypeScript declaration files
25
26
  ]
26
27
  },
27
28
 
29
+ // Global linter options
30
+ {
31
+ linterOptions: {
32
+ reportUnusedDisableDirectives: "error",
33
+ reportUnusedInlineConfigs: "error"
34
+ }
35
+ },
36
+
28
37
  // Base config for all JS files
29
38
  ...compat.extends("airbnb"),
30
39
  {
@@ -55,7 +64,11 @@ module.exports = [
55
64
  "import/no-extraneous-dependencies": "off",
56
65
  // TypeScript handles extensions, not needed for JS imports
57
66
  "import/extensions": "off",
58
- indent: ["error", 2]
67
+ indent: ["error", 2],
68
+ // Allow for...of loops - modern JS syntax
69
+ "no-restricted-syntax": "off",
70
+ // Allow console statements - used for debugging/logging throughout
71
+ "no-console": "off"
59
72
  },
60
73
  settings: {
61
74
  react: {
@@ -122,13 +135,120 @@ module.exports = [
122
135
  "@typescript-eslint/no-use-before-define": ["error"],
123
136
  "@typescript-eslint/no-unused-vars": [
124
137
  "error",
125
- { argsIgnorePattern: "^_" }
138
+ { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
126
139
  ],
127
140
  "@typescript-eslint/no-explicit-any": "error",
128
- "@typescript-eslint/explicit-module-boundary-types": "off"
141
+ "@typescript-eslint/explicit-module-boundary-types": "off",
142
+ "no-undef": "off"
143
+ }
144
+ },
145
+
146
+ // Global rule for all TypeScript files in package/
147
+ // Suppress require() imports - these are intentional for CommonJS compatibility
148
+ // Will be addressed in Phase 3 (breaking changes) - see #708
149
+ {
150
+ files: ["package/**/*.ts"],
151
+ rules: {
152
+ "@typescript-eslint/no-require-imports": "off",
153
+ "global-require": "off",
154
+ "import/no-import-module-exports": "off"
155
+ }
156
+ },
157
+
158
+ // Consolidated override for package/config.ts and package/babel/preset.ts
159
+ {
160
+ files: ["package/babel/preset.ts", "package/config.ts"],
161
+ rules: {
162
+ "@typescript-eslint/no-unused-vars": "off",
163
+ "import/order": "off",
164
+ "import/newline-after-import": "off",
165
+ "import/first": "off",
166
+ "@typescript-eslint/no-explicit-any": "off",
167
+ "no-useless-escape": "off"
168
+ }
169
+ },
170
+
171
+ // configExporter module overrides
172
+ {
173
+ files: ["package/configExporter/**/*.ts"],
174
+ rules: {
175
+ "@typescript-eslint/no-use-before-define": "off",
176
+ "import/no-dynamic-require": "off",
177
+ "class-methods-use-this": "off",
178
+ "import/prefer-default-export": "off",
179
+ "no-underscore-dangle": "off",
180
+ "no-restricted-globals": "off",
181
+ "@typescript-eslint/no-unused-vars": "off",
182
+ "@typescript-eslint/no-explicit-any": "off"
183
+ }
184
+ },
185
+
186
+ // Utils module overrides
187
+ {
188
+ files: [
189
+ "package/utils/inliningCss.ts",
190
+ "package/utils/errorCodes.ts",
191
+ "package/utils/errorHelpers.ts",
192
+ "package/utils/pathValidation.ts",
193
+ "package/utils/getStyleRule.ts",
194
+ "package/utils/helpers.ts",
195
+ "package/utils/validateDependencies.ts",
196
+ "package/webpackDevServerConfig.ts"
197
+ ],
198
+ rules: {
199
+ "@typescript-eslint/no-explicit-any": "off",
200
+ "no-useless-escape": "off"
201
+ }
202
+ },
203
+
204
+ // Plugins and optimization overrides
205
+ {
206
+ files: ["package/plugins/**/*.ts", "package/optimization/**/*.ts"],
207
+ rules: {
208
+ "import/prefer-default-export": "off"
209
+ }
210
+ },
211
+
212
+ // Rules, rspack, swc, esbuild, and other modules
213
+ {
214
+ files: [
215
+ "package/index.ts",
216
+ "package/rspack/index.ts",
217
+ "package/rules/**/*.ts",
218
+ "package/swc/index.ts",
219
+ "package/esbuild/index.ts",
220
+ "package/dev_server.ts",
221
+ "package/env.ts"
222
+ ],
223
+ rules: {
224
+ "@typescript-eslint/no-unused-vars": "off",
225
+ "import/prefer-default-export": "off",
226
+ "no-underscore-dangle": "off"
129
227
  }
130
228
  },
131
229
 
230
+ // Environments module overrides
231
+ {
232
+ files: ["package/environments/**/*.ts"],
233
+ rules: {
234
+ "import/prefer-default-export": "off",
235
+ "no-underscore-dangle": "off"
236
+ }
237
+ },
238
+
239
+ // Type tests are intentionally unused - they test type compatibility
240
+ {
241
+ files: ["package/**/__type-tests__/**/*.ts"],
242
+ rules: {
243
+ "@typescript-eslint/no-unused-vars": "off"
244
+ }
245
+ },
246
+
247
+ // Note: Type-aware rule overrides from main config (e.g., @typescript-eslint/no-unsafe-*,
248
+ // @typescript-eslint/restrict-template-expressions) are intentionally omitted here since
249
+ // fast mode doesn't enable type-aware linting (no parserOptions.project specified).
250
+ // This keeps fast mode performant while maintaining consistency for non-type-aware rules.
251
+
132
252
  // Prettier config must be last to override other configs
133
253
  prettierConfig
134
254
  ]