You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Shakapacker 9.0+ private_output_path integration for server bundles (#2028)
## Summary
This PR integrates Shakapacker 9.0+ `private_output_path` configuration
with React on Rails, eliminating the need for manual
`server_bundle_output_path` configuration and providing automatic
synchronization between webpack and Rails configs.
## Key Changes
### Auto-Detection
- **New**: Automatically detects `private_output_path` from
`shakapacker.yml` (Shakapacker 9.0+)
- Falls back to default `"ssr-generated"` if not configured
- Gracefully handles older Shakapacker versions
### Generator Updates
- **Templates**: Updated to use `private_output_path` for Shakapacker
9.0+
- **Version-aware**: Detects Shakapacker version and generates
appropriate config
- **Backward compatible**: Generates hardcoded paths for older versions
### Doctor Enhancements
- **Detection**: Identifies Shakapacker version and
`private_output_path` support
- **Validation**: Checks for configuration mismatches
- **Recommendations**: Provides upgrade guidance and migration steps
- **Clear messaging**: Success/warning/info messages for all scenarios
### Documentation
- Updated configuration docs with Shakapacker 9.0+ examples
- Added benefits section explaining advantages
- Clear migration path from older versions
## Benefits
1. **Single Source of Truth**: Server bundle path configured once in
`shakapacker.yml`
2. **Automatic Sync**: No manual coordination between webpack and Rails
configs
3. **Better Maintainability**: Reduces configuration duplication
4. **Graceful Degradation**: Works with older Shakapacker versions
5. **Clear Diagnostics**: Doctor command validates configuration
## Testing
- ✅ Comprehensive RSpec tests for auto-detection logic
- ✅ Tests for path normalization edge cases
- ✅ Doctor diagnostic tests for all scenarios
- ✅ Generator tests for version-aware templates
- ✅ All existing tests pass
## Migration Path
For users on Shakapacker 9.0+:
1. Add `private_output_path: ssr-generated` to `config/shakapacker.yml`
2. Remove `config.server_bundle_output_path` from React on Rails
initializer (optional - auto-detected)
3. Run `rails react_on_rails:doctor` to verify
For users on older Shakapacker:
- No changes required - continues to work as before
## Related
Supersedes #1967 (rebased for cleaner history)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/shakacode/react_on_rails/2028)
<!-- Reviewable:end -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Auto-detection/validation of server bundle locations with new
configuration options for private server bundles and SSR behavior.
* **Documentation**
* Major expansion of configuration docs and guides for server rendering,
bundle organization, Shakapacker integration, and migration examples.
* **Tools & Diagnostics**
* Enhanced doctor diagnostics with targeted guidance when bundle paths
or private-output settings mismatch.
* **Tests**
* Added comprehensive tests for Shakapacker integration and
path-normalization scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/core-concepts/webpack-configuration.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,38 @@ default: &default
78
78
79
79
The `bin/switch-bundler` script automatically updates this configuration when switching bundlers.
80
80
81
+
### Server Bundle Configuration (Shakapacker 9.0+)
82
+
83
+
**Recommended**: For Shakapacker 9.0+, use `private_output_path` in `shakapacker.yml` for server bundles:
84
+
85
+
```yaml
86
+
default: &default # ... other config ...
87
+
private_output_path: ssr-generated
88
+
```
89
+
90
+
This provides a single source of truth for server bundle location. React on Rails automatically detects this configuration, eliminating the need to set `server_bundle_output_path` in your React on Rails initializer.
91
+
92
+
In your `config/webpack/serverWebpackConfig.js`:
93
+
94
+
```javascript
95
+
const { config } = require('shakapacker');
96
+
97
+
serverWebpackConfig.output = {
98
+
filename: 'server-bundle.js',
99
+
globalObject: 'this',
100
+
path: config.privateOutputPath, // Automatically uses shakapacker.yml value
101
+
};
102
+
```
103
+
104
+
**Benefits:**
105
+
106
+
- Single source of truth in `shakapacker.yml`
107
+
- Automatic synchronization between webpack and React on Rails
108
+
- No configuration duplication
109
+
- Better maintainability
110
+
111
+
**For older Shakapacker versions:** Use hardcoded paths and manual configuration as shown in the generator templates.
112
+
81
113
Per the example repo [shakacode/react_on_rails_demo_ssr_hmr](https://github.com/shakacode/react_on_rails_demo_ssr_hmr),
82
114
you should consider keeping your codebase mostly consistent with the defaults for [Shakapacker](https://github.com/shakacode/shakapacker).
0 commit comments