This content originally appeared on DEV Community and was authored by Alex Aslam
“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
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
How it works:
- Bun handles JS bundling via
jsbundling-rails
- Rails serves assets through the asset pipeline
- 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)
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
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
4. Migration Guide
- Install Bun:
curl -fsSL https://bun.sh/install | bash
- Add to Rails:
bundle add jsbundling-rails
rails javascript:install:bun
- Update package.json:
{
"scripts": {
"build": "bun build app/javascript/*.* --outdir=app/assets/builds"
}
}
-
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:
- Use Bun for one new feature branch
- Compare CI times and memory usage
- Let the numbers decide
Made the switch? Share your war stories below!
This content originally appeared on DEV Community and was authored by Alex Aslam