Skip to content

Add --rspack option to react_on_rails:install generator #1851

@justin808

Description

@justin808

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:

  1. 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
  2. shakapacker.yml configuration:

    default:
      assets_bundler: 'rspack'
      javascript_transpiler: 'swc'
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions