Skip to content

opal-viteRuby in the Browser with Vite

Write Ruby code and run it in the browser with Vite's lightning-fast development experience

opal-vite logo

Quick Installation

npm / pnpm

bash
# Install the Vite plugin
pnpm add -D vite-plugin-opal

# Install the Ruby gem
gem install opal-vite

Gemfile

ruby
gem 'opal'
gem 'opal-vite'

Basic Setup

vite.config.ts

typescript
import { defineConfig } from 'vite'
import opal from 'vite-plugin-opal'

export default defineConfig({
  plugins: [
    opal({
      loadPaths: ['./app/opal'],
      sourceMap: true
    })
  ]
})

Your First Ruby File

ruby
# app/opal/application.rb
puts "Hello from Ruby!"

class Greeter
  def initialize(name)
    @name = name
  end

  def greet
    puts "Hello, #{@name}!"
  end
end

Greeter.new("World").greet

Playground

Try opal-vite with live demo applications:

See all demos on the Playground page.

Released under the MIT License.