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.
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.
A new app
rails new myapp -m https://raw.githubusercontent.com/tungnt1203/rspack_rails/main/template.rb
cd myapp
bin/devThe 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/devThen 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 # SassAn 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/devSee Migrating for what changes.
- 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, asjsbundling-railsdoes. - 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:doctorchecks Node.js, packages, config and layouts, and says what to fix. - Deploys that work. The installer sets up the
Dockerfilefor Kamal,bin/setupand dev containers.
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/devrunning: the helpers point at/rspack/…, and Rails proxies those requests torspack 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:buildruns beforeassets:precompile, and the asset pipeline serves the result.
| 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.
- 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
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.
Available under the MIT License.
