Esbuild plugin for Rails applications that enables glob imports for Stimulus controllers, ActionCable channels, and other JavaScript files. Current stable version is 1.0.7, released with regular updates. It integrates with jsbundling-rails to replace Webpacker, providing a fast bundling experience for Rails asset pipelines. Differentiators include automatic glob resolution for importing multiple files, seamless integration with Hotwire/Stimulus, and support for jQuery via import hoisting. Requires esbuild as a peer dependency and offers both ESM and CJS configuration examples.
npm install esbuild-railsVerified import paths — ran on the pinned version, not inferred.
Shows basic esbuild configuration with the rails plugin for bundling Rails JavaScript assets.
Use `rails()` (call it) instead of just `rails` in the plugins array.
Use `require` for CommonJS or ensure your config file has `.mjs` extension for ESM.
Switch to `import rails from 'esbuild-rails'` with an `.mjs` config file.
Create a separate file for jQuery setup and import it at the top of your entry point.
Change to `plugins: [rails()]`.
Add `plugins: [rails()]` to your esbuild build options.