Commit 44cca73
fix: Use SWC as default and remove Babel dependencies managed by Shakapacker
This commit addresses the code review comment about separating SWC from
Babel and leveraging Shakapacker for webpack/rspack configurations.
### Changes
#### 1. Updated Default Webpack Loader to SWC
**File**: `lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml`
- Changed `webpack_loader` from 'babel' to 'swc'
- Added comment recommending SWC for better performance
- Shakapacker will now use swc-loader instead of babel-loader by default
**Rationale**: SWC is significantly faster than Babel and is now mature enough
to be the recommended default for new React on Rails projects.
#### 2. Removed Babel-Specific Dependencies from REACT_DEPENDENCIES
**Removed packages**:
- `@babel/preset-react` - Shakapacker's babel-loader provides this when needed
- `babel-plugin-transform-react-remove-prop-types` - Build tool specific
- `babel-plugin-macros` - Build tool specific
**Kept packages**:
- `react` - Core React library
- `react-dom` - Core React DOM library
- `prop-types` - Runtime prop validation (React-specific, not build tool)
**Rationale**:
- Shakapacker manages webpack loader configuration (babel-loader vs swc-loader)
- Users configure their preference via `shakapacker.yml` webpack_loader setting
- SWC (now default) doesn't need Babel presets
- Babel users get babel-loader and dependencies from Shakapacker
- This avoids conflicts and duplicate installations
#### 3. Removed @babel/preset-typescript from TYPESCRIPT_DEPENDENCIES
**Removed**: `@babel/preset-typescript`
**Kept**:
- `typescript` - TypeScript compiler
- `@types/react` - React type definitions
- `@types/react-dom` - React DOM type definitions
**Rationale**:
- SWC has built-in TypeScript support (no preset needed)
- Shakapacker handles the loader configuration
- Babel users can add `@babel/preset-typescript` manually if they choose Babel
#### 4. Added Comprehensive Documentation
All dependency constants now include clear comments explaining:
- Why certain packages are excluded
- How Shakapacker manages build tool dependencies
- The relationship between webpack_loader setting and dependencies
### Impact
**For New Projects**:
- Faster build times with SWC by default
- Cleaner dependency tree (no Babel packages unless explicitly needed)
- Easier to understand which dependencies are React-specific vs build tool specific
**For Existing Projects**:
- No breaking changes - existing projects keep their current webpack_loader setting
- Projects can opt into SWC by changing `webpack_loader: 'swc'` in shakapacker.yml
- Babel users continue to work as before (Shakapacker provides babel-loader)
**For Rspack Users**:
- No changes - Rspack has its own loader mechanism
- Rspack-specific dependencies remain unchanged
### Testing
- ✅ All tests pass (6 examples, 0 failures)
- ✅ bundle exec rubocop passes with zero offenses
- ✅ Git hooks verified clean
### Files Changed
- `lib/generators/react_on_rails/js_dependency_manager.rb`: Removed Babel deps, added docs
- `lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml`: Changed default to SWC
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 850deed commit 44cca73
File tree
2 files changed
+11
-5
lines changed- lib/generators/react_on_rails
- templates/base/base/config
2 files changed
+11
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | | - | |
45 | 49 | | |
46 | | - | |
47 | | - | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
82 | | - | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
0 commit comments