<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tùng Nguyễn</title>
    <description>The latest articles on DEV Community by Tùng Nguyễn (@tng_nguyn_4809cff1d3358).</description>
    <link>https://dev.to/tng_nguyn_4809cff1d3358</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4252934%2F93091afb-d68e-40a7-8f8f-abfa11a85d59.png</url>
      <title>DEV Community: Tùng Nguyễn</title>
      <link>https://dev.to/tng_nguyn_4809cff1d3358</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tng_nguyn_4809cff1d3358"/>
    <language>en</language>
    <item>
      <title>Rails + Rspack: esbuild speed, webpack features, one command</title>
      <dc:creator>Tùng Nguyễn</dc:creator>
      <pubDate>Thu, 19 Nov 2026 04:20:17 +0000</pubDate>
      <link>https://dev.to/tng_nguyn_4809cff1d3358/rails-rspack-esbuild-speed-webpack-features-one-command-13ep</link>
      <guid>https://dev.to/tng_nguyn_4809cff1d3358/rails-rspack-esbuild-speed-webpack-features-one-command-13ep</guid>
      <description>&lt;h2&gt;
  
  
  Why I went looking
&lt;/h2&gt;

&lt;p&gt;I wanted one thing from my Rails frontend setup: change a file and see it on the page, without losing where I was.&lt;/p&gt;

&lt;p&gt;esbuild through jsbundling-rails gets close. Builds are fast and the config is one line. But every change is a full page reload. The modal I opened, the form I half filled, the Stimulus controller's state: gone, every time. Over a day of UI work that adds up to hundreds of small resets.&lt;/p&gt;

&lt;p&gt;Webpacker and Shakapacker give you hot module replacement, but I remember what came with it. A config you are scared to touch, cold builds measured in tens of seconds, and upgrades that meant diffing generated files by hand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rspack.rs" rel="noopener noreferrer"&gt;Rspack&lt;/a&gt; promised both: webpack's features, including HMR, with a Rust core that builds at esbuild speed. So I tried it on a Rails app, and then I wrapped what I learned into a gem, &lt;a href="https://github.com/tungnt1203/rspack_rails" rel="noopener noreferrer"&gt;rspack_rails&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first ten minutes
&lt;/h2&gt;

&lt;p&gt;A new app is three commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails new myapp -m https://raw.githubusercontent.com/tungnt1203/rspack_rails/main/template.rb
&lt;span class="nb"&gt;cd&lt;/span&gt; myapp
bin/dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The template asks which extras you want: Stimulus, TypeScript, React, Tailwind CSS, Sass. &lt;code&gt;bin/dev&lt;/code&gt; starts Rails and &lt;code&gt;rspack serve&lt;/code&gt; side by side.&lt;/p&gt;

&lt;p&gt;Then the part that sold me. I edited a Stimulus controller, and the page did not reload. The controller was swapped in place, and the element I was poking at kept its state. Same with CSS, and with React components through Fast Refresh. When I edited an ERB view, the page reloaded on its own, which is what you want for server-rendered HTML.&lt;/p&gt;

&lt;p&gt;The layout needs only two helpers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;rspack_javascript_tag&lt;/span&gt; &lt;span class="s2"&gt;"application"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"data-turbo-track"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"reload"&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;rspack_stylesheet_tag&lt;/span&gt; &lt;span class="s2"&gt;"application"&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An existing app is &lt;code&gt;bundle add rspack_rails&lt;/code&gt; and &lt;code&gt;bin/rails rspack:install&lt;/code&gt;. An app on importmap-rails or jsbundling-rails can run &lt;code&gt;bin/rails rspack:migrate&lt;/code&gt; from a clean git tree and review the diff.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;p&gt;Rspack is not the fastest at everything, and I think that is the honest headline. esbuild still wins a cold build, by a few hundred milliseconds. Rspack wins the number you feel all day: the rebuild after you save a file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3qzhfepvgrbjt6anuwkx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3qzhfepvgrbjt6anuwkx.png" alt="Bar charts: rebuild after editing one component and production build times for Rspack, esbuild and webpack at 1,000 and 5,000 components" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Measured on an Apple M1, Node 26. Medians of 5 cold builds and 10 watch rebuilds, November 2026.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A rebuild after editing one component took 83 ms with Rspack and 279 ms with esbuild, on 1,000 components. Cold development builds were a tie between the two (0.55 s and 0.54 s), with webpack at 1.46 s. Against webpack, Rspack's production build is 6 to 9 times faster.&lt;/p&gt;

&lt;p&gt;And the rebuild number undersells it. esbuild has no HMR, so after its rebuild the browser still reloads the whole page. Rspack sends only the changed module.&lt;/p&gt;

&lt;p&gt;How I measured: the same generated React 19 + TypeScript app (lodash-es, date-fns), built to ES2022 with source maps. esbuild runs with the flags jsbundling-rails uses, plus &lt;code&gt;--minify&lt;/code&gt;. webpack 5 uses swc-loader, as Shakapacker can. Times include about 0.2 s of &lt;code&gt;npx&lt;/code&gt; and Node startup. Gzipped output was 100 KB for Rspack and webpack, 120 KB for esbuild.&lt;/p&gt;

&lt;p&gt;The proxy rspack_rails puts in front of the dev server costs about 1.8 ms per page navigation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned building the gem
&lt;/h2&gt;

&lt;p&gt;Getting Rspack to run in Rails takes an afternoon. Getting it to stay out of your way took the rest. Four decisions mattered most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Production stays boring.&lt;/strong&gt; Rspack writes to &lt;code&gt;app/assets/builds&lt;/code&gt;, and Propshaft or Sprockets fingerprints and serves the files, the same way jsbundling-rails works. Production never needs Node at runtime, and there is no second manifest system to debug at 2 a.m.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dev server hides behind Rails.&lt;/strong&gt; Pages load scripts from &lt;code&gt;/rspack/...&lt;/code&gt; on the app's own origin, and Rails proxies them to &lt;code&gt;rspack serve&lt;/code&gt;. I learned why the hard way: browsers refuse to start a Web Worker from another origin, so loading straight from &lt;code&gt;localhost:3036&lt;/code&gt; breaks workers. Only the HMR websocket talks to the dev server directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The config is owned, not generated once.&lt;/strong&gt; Webpacker's pain was a config generated on install and never upgraded again. Here the base config, &lt;code&gt;config/rspack/rails.mjs&lt;/code&gt;, belongs to the gem and is rewritten on every upgrade. Your changes live in a callback in &lt;code&gt;rspack.config.mjs&lt;/code&gt;. If someone edits the gem's file by hand, a checksum notices and the edit is backed up before anything is replaced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A doctor that tells you what to type.&lt;/strong&gt; &lt;code&gt;bin/rails rspack:doctor&lt;/code&gt; checks Node.js, packages, config, layouts, &lt;code&gt;Procfile.dev&lt;/code&gt;, the Dockerfile and the dev server. Every warning ends with the command that fixes it. It is the first thing I run when something looks off.&lt;/p&gt;

&lt;p&gt;The bugs that taught me the most came from real apps, not tests. Migrating an app with two layouts showed that the admin layout silently lost its JavaScript. That fix shipped in 1.0.0.rc2.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should not use it
&lt;/h2&gt;

&lt;p&gt;If your app has a few Stimulus controllers and no npm packages that need bundling, stay on importmap-rails. It is the Rails default for good reasons: no Node, no build step, nothing to learn.&lt;/p&gt;

&lt;p&gt;If you bundle but never miss HMR, esbuild through jsbundling-rails is a fine choice. It is simple, very fast on cold builds, and has fewer moving parts than any webpack-style tool.&lt;/p&gt;

&lt;p&gt;rspack_rails is for the point where you want more than that: React or TypeScript with Fast Refresh, code splitting, CSS modules, loaders, or the webpack plugin you already know. That is where I kept wishing for webpack's features without webpack's wait.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;rspack_rails 1.0 is on RubyGems. It supports Rails 7.2 and 8.x, Propshaft and Sprockets, and npm, Yarn, pnpm and bun.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails new myapp -m https://raw.githubusercontent.com/tungnt1203/rspack_rails/main/template.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Code and docs: &lt;a href="https://github.com/tungnt1203/rspack_rails" rel="noopener noreferrer"&gt;github.com/tungnt1203/rspack_rails&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Demo app: &lt;a href="https://github.com/tungnt1203/rspack_rails-demo" rel="noopener noreferrer"&gt;rspack_rails-demo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you try it on a real app, I would love to hear what broke. The best fixes so far came from exactly that. Open an issue, or tell me in the comments.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>javascript</category>
      <category>webpack</category>
    </item>
  </channel>
</rss>
