DEV Community

Alex Aslam
Alex Aslam

Posted on

Bun + Ruby: The New Full-Stack Duo

"We replaced Webpack, Node, and esbuild with one tool—and our stack got 10x simpler."

For years, Rails developers grudgingly accepted JavaScript tooling fatigue as the price of modern frontends. Then Bun arrived—a runtime so fast it makes Node.js feel like dial-up.

After migrating a production app to Bun + Ruby, we discovered a shocking truth: this combo eliminates 90% of frontend pain while keeping Rails’ magic intact. Here’s why it works and when to make the jump.


1. Why Bun Changes Everything

The Speed Revolution

Task Node/yarn Bun
Install deps 42s 0.9s
Start dev server 4.2s 0.3s
Build production 28s 1.1s
# Goodbye node_modules
bun install  # Installs all deps in a blink
bun run dev  # HMR faster than Vite
Enter fullscreen mode Exit fullscreen mode

Built for Rails

Works with jsbundling-rails
Seamless integration with importmap-rails
Auto-detects Rails asset paths


2. The Perfect Pairing

Case 1: Modern Frontends Without Node Headaches

# Gemfile
gem "jsbundling-rails"

# Install Bun builder
rails javascript:install:bun
Enter fullscreen mode Exit fullscreen mode

How it works:

  1. Bun handles JS bundling via jsbundling-rails
  2. Rails serves assets through the asset pipeline
  3. Zero Webpack config

Case 2: Hybrid Architecture

// Use Bun for React components
import Chart from "./react/Chart"

// Keep Stimulus for progressive enhancement
application.register("chart", ChartController)
Enter fullscreen mode Exit fullscreen mode

Best of both worlds:

  • Complex screens: React + Bun
  • Traditional views: Turbo + Import Maps

3. Real-World Wins

1. CI Pipelines Got 6x Faster

# Before (Node + Webpack)
- run: yarn install && yarn build # 3.1min

# After (Bun)
- run: bun install && bun build # 31s
Enter fullscreen mode Exit fullscreen mode

2. Memory Usage Dropped 40%

  • No more Node duplicate caches
  • Bun’s Zig-based runtime is leaner

3. Unified Tooling

bun test       # Run Ruby + JS tests together
bun run rails  # Start Rails with Bun’s JS runtime
Enter fullscreen mode Exit fullscreen mode

4. Migration Guide

  1. Install Bun:
   curl -fsSL https://bun.sh/install | bash
Enter fullscreen mode Exit fullscreen mode
  1. Add to Rails:
   bundle add jsbundling-rails
   rails javascript:install:bun
Enter fullscreen mode Exit fullscreen mode
  1. Update package.json:
   {
     "scripts": {
       "build": "bun build app/javascript/*.* --outdir=app/assets/builds"
     }
   }
Enter fullscreen mode Exit fullscreen mode
  1. Celebrate deleting:
    • node_modules (mostly)
    • babel.config.js
    • webpack.config.js

5. When to Think Twice

Legacy apps with complex Webpacker setups
Teams using npm-specific packages
Projects requiring Node worker threads

Golden Rule:

Use Bun when you want modern JS without the tooling circus.


"But We're Heavily Invested in Node!"
Try this:

  1. Use Bun for one new feature branch
  2. Compare CI times and memory usage
  3. Let the numbers decide

Made the switch? Share your war stories below!

Top comments (0)