Closed thebravoman closed 4 years ago
Actually I found this one - https://github.com/rails/webpacker/issues/348#issuecomment-599262544. What I actually was searching for was the part. Whether y
// The usual stuff
const application = Application.start()
const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context))
// Pointed at my gem
const gem_context = require.context('my_gem/app/javascript/packs/controllers', true, /\.js$/)
application.load(definitionsFromContext(gem_context))
and that Application could accept a few load(s)
See https://github.com/rails/webpacker/blob/master/docs/engines.md too. Stimulus is just a JavaScript library and doesn't play a direct role here. Feel free to start a new discussion on https://discourse.stimulusjs.org. ✌️
Thanks. I understand the stimulus does not play a role there and that stimulus is not dependent on this. But stimulus on rails with webpacker I would assume is a common case.
There could be a section on stimulus handbook that is "# rails & webpack" and has a link to "webpacker and engines" and a place where rails specific things could be added. Or this could be added as an additional paragraph to "Using with webpack" specifically that you could call application.load two times and could load the controllers from more than one folder.
Could not find it in the documentation so I though it should probably be added on how to use a stimulus controller located in an engine.
The engine is providing the controller. The host app must use it.