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.
npm install stimulus-vite-helpersVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a Stimulus application and registering all controllers found via Vite's `import.meta.glob`.
Migrate your project to use ESM and Vite. If using a different bundler, seek specific plugins or alternative approaches for Stimulus controller registration.
Ensure your project is built and served using Vite. If migrating away from Vite, you will need to replace `import.meta.glob` with an equivalent mechanism for your new bundler.
Always use `{ eager: true }` when defining the `controllers` glob for `registerControllers` to ensure all controllers are immediately available upon application start.Verify your glob pattern matches the actual file structure of your Stimulus controllers. Use specific paths if your controllers are not in a recursive subdirectory, e.g., `./controllers/*.js`.
Ensure `import { Application } from 'stimulus'` is correct and Stimulus is properly installed as an ESM module. Check your `package.json` for `stimulus`.Ensure your file ends with `.js` and your `package.json` contains `"type": "module"`, or explicitly name the file `.mjs` to force ES module interpretation. Verify your Vite configuration is correct.
While `stimulus-vite-helpers` itself doesn't directly use `process`, ensure any other dependencies or custom code intended for browser use do not rely on `process` or other Node.js globals without Vite's `define` configuration for browser compatibility.