Registry / web-framework / esbuild-rails

esbuild-rails

JSON →
library1.0.7jsnpmunverified

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-rails
INSTALL
IMPORT
SIG · ESBUILD-RAILS
E
esbuild-rails
web-frameworkjavascriptv1.0.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import rails from 'esbuild-rails'
const rails = require('esbuild-rails')
ESM syntax recommended; CJS via require also works but may be deprecated in future.
rails function
plugins: [rails()]
plugins: [rails]
The plugin must be called as a function, not passed as a reference.
Path resolution
const path = require('path'); const rails = require('esbuild-rails')
import path from 'path' in CJS context
Use CJS require for the example config file if not using ES modules.

Shows basic esbuild configuration with the rails plugin for bundling Rails JavaScript assets.

const path = require('path'); const rails = require('esbuild-rails'); require('esbuild').build({ entryPoints: ['application.js'], bundle: true, outdir: path.join(process.cwd(), 'app/assets/builds'), absWorkingDir: path.join(process.cwd(), 'app/javascript'), plugins: [rails()], }).catch(() => process.exit(1));
Debug
Known issues
gotchaThe plugin function must be called: `rails()` not `rails`. Passing the function reference directly will cause a build error.
fix
Use `rails()` (call it) instead of just `rails` in the plugins array.
affects: >=0.0.1
breakingESM and CJS module systems are mixed in examples – using `import` statements in a CommonJS config file may cause syntax errors.
fix
Use `require` for CommonJS or ensure your config file has `.mjs` extension for ESM.
affects: >=1.0.0
deprecatedThe `require('esbuild-rails')` pattern may be deprecated in future versions in favor of ESM imports.
fix
Switch to `import rails from 'esbuild-rails'` with an `.mjs` config file.
affects: >=1.0.0
gotchaImporting jQuery via separate file relies on import hoisting; placing the import after other code may not work as expected.
fix
Create a separate file for jQuery setup and import it at the top of your entry point.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: rails is not a function
Calling the plugin as a reference rather than invoking it: `plugins: [rails]` instead of `plugins: [rails()]`.
fix
Change to `plugins: [rails()]`.
Error: Could not resolve './src/**/*'
Glob patterns require the esbuild-rails plugin to be active; missing plugin in esbuild config.
fix
Add `plugins: [rails()]` to your esbuild build options.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency – esbuild is required as the underlying bundler.
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-rails — npm install esbuild-rails · libregistry