Generate a better stimulus name for component controller

Using the helper `definitionsFromContext` generate quite long name for
stimulus controller in component, ie :
`tag-list-input-component--tag-list-input`.
This custom loader will generate much more readable name, ie L
`tag-list-input`. It's expecting the following pattern :
ofn_component/ofn_controller.js and will fall back to the default
of replacing "_" by "- and "/" by "--" for controller not matching
the pattern.
This commit is contained in:
Gaetan Craig-Riou
2025-09-10 15:03:31 +10:00
parent da66a2947c
commit ad1ce00223
2 changed files with 29 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
// This controller will be called "example-component--example", ie "component-subdirectory--js-file-name"
// This controller will be called "example", ie "js-file-name" minus the "_controller.js"
// see controller/index.js for more info
import { Controller } from "stimulus";
export default class extends Controller {}