Ask A Question

Notifications

You’re not receiving notifications from this thread.

What is the best way to import node_modules CSS in a Rails 7 Esbuild project?

Stéphane Paquet asked in Rails

Rails 7.0
Ruby 3.0.3
Esbuild / Tailwind
Question: what is the best way to import the CSS from a node package. After running the yarn add command, the JS loads very easily but as you know adding import css in application.js will lead in having the application.css overwritten, what is not intended.
I could copy the node_module css files to the assets/javascript folder and the use @import in the application.tailwind.css file but that means that every time the node_module is upgraded (or during deployment) something will break...
I was considering adding Rails.application.config.assets.paths << "node_modules" in the assets.rb file but not sure this is a good practice.
What are your recommendations?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.