Stimulus Vite Helpers

3.1.0 · active · verified Sun Apr 19

stimulus-vite-helpers is a utility package designed to simplify the registration of Stimulus.js controllers within applications that utilize Vite.js as their build tool. It provides a `registerControllers` helper function, which works in conjunction with Vite's `import.meta.glob` feature to automatically discover and register controllers across your project. The current stable version is 3.1.0, and the project appears to follow a release cadence tied to new features or improvements in Stimulus or Vite ecosystems. Key differentiators include its tight integration with Vite's native glob importing, streamlining a common Stimulus setup pattern, and its origin from the Jumpstart Rails with Vite.js template, implying robust integration with Rails applications using Vite. It does not provide HMR itself but suggests `vite-plugin-stimulus-hmr` for that functionality. This library is crucial for those building modern web applications with the Stimulus framework and Vite bundler, especially in Ruby on Rails contexts where `vite_rails` is often used.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing a Stimulus application and registering all controllers found via Vite's `import.meta.glob`.

import { Application } from 'stimulus';
import { registerControllers } from 'stimulus-vite-helpers';

// Initialize the Stimulus application
const application = Application.start();

// Use Vite's import.meta.glob to discover all Stimulus controllers.
// The pattern './**/*_controller.js' will match all files ending in '_controller.js'
// recursively from the current directory. { eager: true } ensures they are imported immediately.
const controllers = import.meta.glob('./**/*_controller.js', { eager: true });

// Register the discovered controllers with the Stimulus application.
registerControllers(application, controllers);

console.log('Stimulus application started with controllers:', Object.keys(controllers).length);

view raw JSON →