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
.
npm install --save-dev @cozy-web/esbuild-plugin-stimulus
In your esbuild script:
// build.js
const esbuild = require('esbuild')
const pluginStimulus = require('@cozy-web/esbuild-plugin-stimulus')
esbuild
.build({
plugins: [pluginStimulus()],
// ...
})
.catch(() => process.exit(1))
And in your application (similar to using webpack):
// app.js
import { Application } from '@hotwired/stimulus'
import { definitions } from 'stimulus:./controllers'
const app = Application.start()
app.load(definitions)
Due to the limitations of watchFiles
and watchDirs
:
A rebuild will be triggered if any file in the
watchFiles
array has been changed since the last build. Change detection is somewhat complicated and may check the file contents and/or the file's metadata. A rebuild will also be triggered if the list of directory entries for any directory in thewatchDirs
array has been changed since the last build. Note that this does not check anything about the contents of any file in these directories, and it also does not check any subdirectories. Think of this as checking the output of the Unixls
command.
This plugin can't detect the changes in newly created directories when using watch mode. You have to restart ebuild to make it aware of the changes.
Apache License 2.0