-
-
Notifications
You must be signed in to change notification settings - Fork 638
Description
Summary
Add a --rspack
option to the react_on_rails:install
generator to create demos configured for Rspack instead of Webpack by default.
Motivation
Rspack provides 10-20x faster build times compared to Webpack while maintaining API compatibility. The demos/basic-v16
demo (PR #20) demonstrates a complete working implementation with:
- Rspack configuration that works seamlessly with React on Rails
- Unified webpack/rspack configuration approach
- Proper HMR and React Fast Refresh setup
- Complete migration documentation
This PR proves that React on Rails works excellently with Rspack and provides a template for the generator.
Proposed Implementation
Add a --rspack
flag to the install generator:
rails generate react_on_rails:install --rspack
Changes needed:
-
Package dependencies: Install rspack packages instead of webpack
@rspack/core
,@rspack/cli
,@rspack/plugin-react-refresh
rspack-manifest-plugin
- Use SWC instead of Babel by default
-
shakapacker.yml configuration:
default: assets_bundler: 'rspack' javascript_transpiler: 'swc'
-
Webpack configuration: Use conditional bundler detection (already demonstrated in basic-v16)
Reference Implementation
PR #20 (demos/basic-v16
) provides a complete reference implementation including:
- Correct package.json dependencies for rspack
- Unified config/webpack/ configuration that works for both bundlers
- Comprehensive migration documentation
- bin/switch-bundler script for easy bundler switching
Benefits
- 10-20x faster builds for new React on Rails projects
- Better developer experience with faster HMR
- Future-proof - Rspack is gaining widespread adoption
- Easy migration path - Users can still switch back to webpack if needed
Additional Context
The basic-v16 demo includes:
- Full migration guide at
docs/webpack-to-rspack-migration.md
- Performance benchmarks (250ms vs 3.5s builds)
- Troubleshooting documentation
- Script for switching between bundlers
This generator option would help new projects benefit from Rspack's performance immediately while maintaining the flexibility to use Webpack if needed.