Integrating Bun with Vite Ruby for Lightning-Fast Frontend Builds

With the recent release of Bun and its newfound support for Vite, coupled with Ruby on Rails 7.1 incorporating native support for Bun, developers can now enhance their web development workflow significantly. Here is the effortless process of enabling Bun for Vite Ruby, ultimately streamlining your front-end builds.

Bun plus Vite Ruby

Getting Started: Creating a Shim Bin

To kick things off, you need to create a shim bin. Navigate to the bin/shims directory and add a file named vite with the following content:

#!/usr/bin/env bash

set -eo pipefail

bunx vite "$@"

Configuring Vite Ruby to Use the Shim Bin

Next up, update your Vite Ruby configuration file (config/vite.json). Specify the path to the newly created shim bin using the viteBinPath attribute.

Here’s an example:

  "all": {
    "viteBinPath": "bin/shims/vite"
    // ...
  // ...

By setting the viteBinPath to your shim bin, you’re instructing Vite Ruby to leverage Bun during the build process.

The Results: A Faster Workflow

The impact of this integration is tangible. Migrating to Bun has slashed asset processing time by 1-2 minutes, from installing dependencies to compiling assets. This optimization is particularly crucial for teams practicing Continuous Delivery, where quicker builds can significantly boost overall productivity.

Paul Keen is an Open Source Contributor and a Chief Technology Officer at JetThoughts. Follow him on LinkedIn or GitHub.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories.