Integrations
Ruby back-end servers
-
Rails integration is provided for both Webpacker and Sprockets. Rake tasks are provided to assist with the configuration. If you’re using the new jsbundling Rails 7 plugin, you’ll likely want to look at the front-end bundling instructions below.
-
Sinatra views may be used to produce JavaScript from Ruby, enabled by
require "ruby2js/sinatra" -
CGI scripts may also be used to produce JavaScript from Ruby. This can be combined with Wunderbar to produce both HTML and JavaScript, enabled by
require "wunderbar/script". -
Haml scripts can be written in Ruby via a filter enabled by
require "ruby2js/haml"
JavaScript front-end build tools
Vite is the recommended build tool for Ruby2JS projects. The vite-plugin-ruby2js package provides Hot Module Replacement, source maps, and framework-specific presets (Rails, Juntos, and more). See the Vite Integration guide for details.
The ESM filter lets you author import and export statements, and the autoexports and autoimports options can often relieve you of the need to do so.
JavaScript bundlers
An esbuild plugin is available for fast builds of CLI tools, serverless functions, and other non-web projects. For web applications with hot module replacement, see the Vite integration.
The ESM filter and autoexports and autoimports options are useful with bundlers.
Web Components
Filters are available for Lit, React, and Stimulus. The React filter also supports Preact.
Node.js
A Node filter is available, as well as a register module. In most cases it will be the CJS filter rather than the ESM filter that you will want to use.
Ruby2JS on Rails
The Rails filter enables transpiling entire Rails applications to JavaScript. Models, controllers, routes, and ERB templates are converted to run in browsers or JavaScript server runtimes (Node.js, Bun, Deno).
This approach is ideal for offline-first applications, static deployment, and edge computing. See the Ruby2JS on Rails guide for details.