Skip to content

Can't include files from custom.js when using esbuild and propshaft #550

@chemica

Description

@chemica

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions