-
Notifications
You must be signed in to change notification settings - Fork 176
Description
Great admin system! I'm loving it so far!
I do have a bit of a headache with the config though. As I'm using esbuild and propshaft I can't use pre-processing "require comments" or Javascript imports in the custom.js file. This means I can only really add plain JS, which means I don't have access to Stimulus and I can't structure my files neatly.
I can use hooks to add a JS file that I build in my Rails app, which works. However, to use Stimulus I need to import Application and Controller, which pulls the whole library into my built file. That means the user is downloading Stimulus twice.
I've tried finding the Stimulus application in window object, and it is there, but I can't access the Controller export that way so I'm still stuck.
I can progress for now, as pulling Stimulus in twice doesn't seem to cause any issues (thus far), but it's a stumbling block in my quest to optimise the download size of my pages.
Am I missing something, or is it a "bug" or edge case that could be fixed with a workaround? For example, a hacky way would be adding the Stimulus Controller to the Stimulus app or to window as a property, so I could access both through the window object in the built code.
Is there an obvious way of fixing this that I'm missing? Or a less hacky fix to allow structured JS builds, using Stimulus, without bloating the final JS download?