Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.51 KB

README.md

File metadata and controls

62 lines (43 loc) · 1.51 KB

esbuild-plugin-stimulus

esbuild plugin for automatically loading Stimulus controllers from a folder. For example, if you create controllers/users/list_item_controller.js, then your Stimulus controller will be available as users--list-item.

Install

npm install --save-dev esbuild-plugin-stimulus

Usage

In your esbuild script:

// build.js

const esbuild = require('esbuild');
const { stimulusPlugin } = require('esbuild-plugin-stimulus');

esbuild.build({
  plugins: [stimulusPlugin()],
  // ...
}).catch(() => process.exit(1));

And in your application (similar to using webpack):

// app.js

import { Application } from 'stimulus';
import { definitions } from 'stimulus:./controllers';

const app = Application.start();
app.load(definitions);

If you are using TypeScript, add a declaration file like the following to your project to provide type information for stimulus: imports:

// esbuild-plugin-stimulus.d.ts

declare module 'stimulus:*' {
  import type { Definition } from '@hotwired/stimulus';
  export const definitions: Definition[];
}

License

Apache 2.0