Importmap and css

What is considered the best practice Rails Way™ to handle JS dependencies that come with their own stylesheets or other non-js assets for applications using importmap? I’ve struggled with this poorly documented issue since starting to use importmap and currently I have several NPM modules installed using importmaps where I have manually added the relevant stylesheets to /vendor/css/ and imported it in my application’s stylesheet, but of course this kinda defeats the purpose of using a tool like bin/importmap to install dependencies since I cannot get updates to these stylesheets and they will get left behind if I unpin the relevant module JS.

What are large-scale production apps doing for this? Is there some way to manage JS and CSS dependencies together without actually using NPM seperately to manage dependencies and then linking them through importmaps or something?

1 Like

Can you explain what you mean by that?

importmaps only handles JavaScript, and it only vendors JavaScript.

If you’re installing npm packages into node_modules, you can add node_modules to your sprocket paths and then import any css/sass in the node_modules into your CSS pipeline.

Does that help? I can be more specific or help alternatively with propshaft/cssbundling/etc.