-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load Stimulus controller from app/component #15
Comments
benoittgt
added a commit
to benoittgt/esbuild-rails
that referenced
this issue
Apr 25, 2023
If you try to register Stimulus controllers from another path than `controller/` the regex do not process it properly. Also we do not need to add `controllers--` for controller in controller folder. See [doc](https://stimulus.hotwired.dev/handbook/installing#controller-filenames-map-to-identifiers). Examples with dedicated stimulus view components controllers. ``js import { Application } from "@hotwired/stimulus" const application = Application.start() window.Stimulus = application import componentControllers from '../components/**/*_controller.js'; componentControllers.forEach((controller) => { application.register(controller.name, controller.module.default) }); import controllers from "./**/*_controller.js" controllers.forEach((controller) => { application.register(controller.name, controller.module.default) }) ``` To try this code. ```js const ok =[ 'controllers/release_target_controller.js', 'controllers/toggle_controller.js', '../components/deploy_slack_pref_component_controller.js' ].map((module) => module .replace(/_controller.[j|t]s$/, "") .replace(/^controllers\//, "") // do not namespace controllers in controllers directory .replace(/\.\.\//, "") // do not use parent folder anotation for controller name .replace(/\//g, "--") .replace(/_/g, '-') ) console.log(ok) // [ // 'release-target', // 'toggle', // 'components--deploy-slack-pref-component' // ] ``` Fix: excid3#15
benoittgt
added a commit
to benoittgt/esbuild-rails
that referenced
this issue
Apr 25, 2023
If you try to register Stimulus controllers from another path than `controller/` the regex do not process it properly. Also we do not need to add `controllers--` for controller in controller folder. See [doc](https://stimulus.hotwired.dev/handbook/installing#controller-filenames-map-to-identifiers). Examples with dedicated stimulus view components controllers. ``js import { Application } from "@hotwired/stimulus" const application = Application.start() window.Stimulus = application import componentControllers from '../components/**/*_controller.js'; componentControllers.forEach((controller) => { application.register(controller.name, controller.module.default) }); import controllers from "./**/*_controller.js" controllers.forEach((controller) => { application.register(controller.name, controller.module.default) }) ``` To try this code. ```js const ok =[ 'controllers/release_target_controller.js', 'controllers/toggle_controller.js', '../components/deploy_slack_pref_component_controller.js' ].map((module) => module .replace(/_controller.[j|t]s$/, "") .replace(/^controllers\//, "") // do not namespace controllers in controllers directory .replace(/\.\.\//, "") // do not use parent folder anotation for controller name .replace(/\//g, "--") .replace(/_/g, '-') ) console.log(ok) // [ // 'release-target', // 'toggle', // 'components--deploy-slack-pref-component' // ] ``` Fix: excid3#15
Hi @benoittgt Same here ! We ended up with some : import controllers from "./**/*_controller.js"
controllers.forEach((controller) => {
application.register(controller.name.replace('controllers--', ''), controller.module.default)
})
import componentControllers from "../components/**/*_controller.js"
componentControllers.forEach((controller) => {
application.register(controller.name.replace('..--components--', ''), controller.module.default)
}) Thx, |
benoittgt
added a commit
to benoittgt/esbuild-rails
that referenced
this issue
Apr 26, 2023
If you try to register Stimulus controllers from another path than `controller/` the regex do not process it properly. Also we do not need to add `controllers--` for controller in controller folder. See [doc](https://stimulus.hotwired.dev/handbook/installing#controller-filenames-map-to-identifiers). Examples with dedicated stimulus view components controllers. ``js import { Application } from "@hotwired/stimulus" const application = Application.start() window.Stimulus = application import componentControllers from '../components/**/*_controller.js'; componentControllers.forEach((controller) => { application.register(controller.name, controller.module.default) }); import controllers from "./**/*_controller.js" controllers.forEach((controller) => { application.register(controller.name, controller.module.default) }) ``` To try this code. ```js const ok =[ 'controllers/release_target_controller.js', 'controllers/toggle_controller.js', '../components/deploy_slack_pref_component_controller.js' ].map((module) => module .replace(/_controller.[j|t]s$/, "") .replace(/^controllers\//, "") // do not namespace controllers in controllers directory .replace(/\.\.\//, "") // do not use parent folder anotation for controller name .replace(/\//g, "--") .replace(/_/g, '-') ) console.log(ok) // [ // 'release-target', // 'toggle', // 'components--deploy-slack-pref-component' // ] ``` Fix: excid3#15
Thanks @kevynlebouille I just open a patch to fix that. :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
First thanks a lot for this project, the video you did on jquery and jquery-ui.
With view component, you can have Stimulus file that are in
app/component
folder.So I did this in my
app/javascript/controller.js
It ouputs controller name but the name looks wrong on the component folder where I host at the moment only one Stimulus file.
The text was updated successfully, but these errors were encountered: