Stimulus has built-in support for Webpacker, which makes sense, and the docs say the place the controllers in app/javascript/packs/controllers
. From app/javascript/packs/application.js
:
const application = Application.start()
const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context))
However, according to the rails/webpacker docs:
“Packs” is a special directory made only for webpack entry files so don’t put anything here that you don’t want to link in your views.
So I was expecting app/javascript/controllers
, not app/javascript/packs/controllers
.
I couldn’t find where this is explained anywhere. Obviously the fix is to either go with it, or change to require.context("../controllers", true, /\.js$/)
.
I’d like to be able to be as idiomatic as possible, while also being able to explain to people why things are how they are. Any background info or something on this?