0.0
The project is in a healthy, maintained state
Bundle Rails JavaScript with Rspack: one-command installer, dev server with hot module replacement, Stimulus controller autoloading and a setup doctor. Works with Propshaft and Sprockets.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 7.2, < 9
 Project Readme

rspack_rails

Gem Version CI

Bundle your Rails app's JavaScript and CSS with Rspack, the Rust-powered, webpack-compatible bundler, with hot module replacement in development and the asset pipeline in production.

Editing a view and a Stimulus controller in the rspack_rails demo app

In the demo app: a Tailwind class added to an ERB view shows up after an automatic reload, then an edited Stimulus controller is swapped in place without one.

The demo app also runs live: React, CSS modules in Sass, lazy chunks, a Web Worker, Turbo Streams over Action Cable and a page with its own bundle, deployed with Kamal.

Quick start

A new app

rails new myapp -m https://raw.githubusercontent.com/tungnt1203/rspack_rails/main/template.rb
cd myapp
bin/dev

The template asks which extras you want (Stimulus, TypeScript, React, Tailwind CSS, Sass). To skip the questions: RSPACK_FEATURES=stimulus,typescript,tailwind rails new myapp -m …

An existing app

bundle add rspack_rails
bin/rails rspack:install
bin/dev

Then add only what you need:

bin/rails rspack:install:stimulus     # Stimulus, with controller autoloading
bin/rails rspack:install:typescript   # type checking (TypeScript already compiles)
bin/rails rspack:install:react        # React, with Fast Refresh
bin/rails rspack:install:tailwind     # Tailwind CSS v4
bin/rails rspack:install:sass         # Sass

An app on importmap-rails or jsbundling-rails

git commit -am "Before rspack"   # rspack:migrate needs a clean tree
bin/rails rspack:migrate
git diff
bin/dev

See Migrating for what changes.

What you get

  • Hot updates in development. JavaScript, CSS, Stimulus controllers and React components are swapped in place. Editing a view reloads the page.
  • The asset pipeline in production. Rspack writes to app/assets/builds, and Propshaft or Sprockets fingerprints and serves the files, as jsbundling-rails does.
  • No manifests to maintain. Stimulus controllers and React components are found by file name.
  • TypeScript, CSS modules, Tailwind CSS v4, Sass, plus images and fonts imported from JavaScript or CSS.
  • A doctor. bin/rails rspack:doctor checks Node.js, packages, config and layouts, and says what to fix.
  • Deploys that work. The installer sets up the Dockerfile for Kamal, bin/setup and dev containers.

How it works

            page + /rspack/*                 /rspack/* (proxied)
browser  ───────────────────▶  Rails :3000  ────────────────────▶  rspack serve :3036
   │                                                                      ▲
   └───────────────────────────── HMR websocket ──────────────────────────┘

Put two helpers in your layout:

<%= rspack_javascript_tag "application", "data-turbo-track": "reload" %>
<%= rspack_stylesheet_tag "application" %>
  • bin/dev running: the helpers point at /rspack/…, and Rails proxies those requests to rspack serve. Only the HMR websocket goes to the dev server directly.
  • Dev server stopped: the helpers fall back to the last build in app/assets/builds.
  • Production: rspack:build runs before assets:precompile, and the asset pipeline serves the result.

Documentation

Guide What's in it
Usage Entry points, #/ imports, Stimulus, CSS, Tailwind, Sass, React, TypeScript, images and fonts
Production Builds, source maps, Subresource Integrity, Docker and Kamal, dev containers, bundle analysis
Configuration Customizing rspack.config.mjs, environment variables, every rake task
Migrating Moving from importmap-rails, jsbundling-rails, tailwindcss-rails or dartsass-rails
Upgrading Updating the gem, and what stays stable from 1.0
Troubleshooting Common errors and what to do about them

How fast is it? Rails + Rspack: esbuild speed, webpack features, one command compares Rspack with esbuild and webpack; benchmark/ has the script to run it yourself.

rspack_rails-demo is a Rails 8 app with TypeScript Stimulus controllers, Tailwind CSS, code splitting and a second entry point. Its git history has one commit per installer, so you can see exactly what each one changes.

Requirements

  • Ruby 3.2+ and Rails 7.2+ (Propshaft or Sprockets)
  • Node.js 20.19+ or 22.12+
  • bun, yarn, pnpm or npm, detected from your lockfile
  • Rspack 2, installed for you

Contributing

Bug reports, fixes and docs improvements are welcome. CONTRIBUTING.md covers setting up, finding your way around the code and which tests to run for which change. Please follow the Code of Conduct.

License

Available under the MIT License.