Registry / web-framework / esbuild-plugin-stimulus

esbuild-plugin-stimulus

JSON →
library0.2.0jsnpmunverified

An esbuild plugin for automatically loading Stimulus controllers from a folder, inspired by the webpack helpers. Version 0.2.0 is current and stable. It maps controller file names to Stimulus identifier conventions (e.g., `users/list_item_controller.js` becomes `users--list-item`). Ships TypeScript declarations. No breaking changes known, but usage requires both esbuild and Stimulus (or @hotwired/stimulus). Lightweight, single-purpose plugin with no runtime dependencies.

npm install esbuild-plugin-stimulus
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-STI
E
esbuild-plugin-stimulus
web-frameworkjavascriptv0.2.0
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.

stimulusPlugin
const { stimulusPlugin } = require('esbuild-plugin-stimulus')
import stimulusPlugin from 'esbuild-plugin-stimulus'
Uses CommonJS with named export; no default export. For ESM, use const { stimulusPlugin } = await import('esbuild-plugin-stimulus').
definitions
import { definitions } from 'stimulus:./controllers'
import definitions from 'stimulus:./controllers'
Named export from a virtual module with stimulus: prefix. Path is relative to project root.
Definition
import type { Definition } from '@hotwired/stimulus'
Type import for the Definition type used in the .d.ts declaration. Only needed in TypeScript.

Sets up esbuild with the plugin and uses the virtual module to load controllers from the ./controllers directory.

// build.js (CommonJS) const esbuild = require('esbuild'); const { stimulusPlugin } = require('esbuild-plugin-stimulus'); esbuild.build({ entryPoints: ['app.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [stimulusPlugin()], }).catch(() => process.exit(1)); // app.js (ESM) import { Application } from '@hotwired/stimulus'; import { definitions } from 'stimulus:./controllers'; const app = Application.start(); app.load(definitions); // esbuild-plugin-stimulus.d.ts (optional, for TypeScript) declare module 'stimulus:*' { import type { Definition } from '@hotwired/stimulus'; export const definitions: Definition[]; }
Debug
Known issues
gotchaPlugin requires the `stimulus:` import prefix to work; using a bare path will not trigger the plugin.
fix
Always use `from 'stimulus:./controllers'` (with the prefix) in your application code.
affects: >=0.1.0
gotchaThe import path in `stimulus:./controllers` is relative to the project root (where esbuild is invoked), not relative to the importing file.
fix
Ensure the path after `stimulus:` resolves from your project root. For example, if your app is in `src/app.js` and controllers in `src/controllers`, use `'stimulus:./src/controllers'`.
affects: >=0.1.0
deprecatedIf you are using the older 'stimulus' package (before it was renamed to @hotwired/stimulus), the import paths may still work, but it is recommended to update.
fix
Replace `import { Application } from 'stimulus'` with `import { Application } from '@hotwired/stimulus'`.
affects: >=0.1.0
Errors
Common errors & fixes
TypeScript error: Cannot find module 'stimulus:./controllers' or its corresponding type declarations.
Missing type declaration file for the virtual module.
fix
Add a `esbuild-plugin-stimulus.d.ts` file (as shown in the quickstart) to your project.
Error: [esbuild] Plugin 'stimulus' returned an error: Could not resolve 'stimulus:./controllers'
The stimulus plugin is not included in the esbuild plugins array.
fix
Add `stimulusPlugin()` to the `plugins` array in your esbuild configuration.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency; provides the plugin API and build system
@hotwired/stimulusoptionalruntime peer; needed for Application and types
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-plugin-stimulus — npm install esbuild-plugin-stimulus · libregistry