Description
It would be useful for a Tailwind + Rails integration to include a way to use images from the asset pipeline. As far as I know it's not possible to use asset-url
in any of the locations relevant to tailwind:
- In the
application.tailwind.css
as a custom utility: This half-works, asasset-url
is put in thetailwind.css
output file. However, the asset pipeline ignores it because it isn't processed. Maybe I can enable this somehow? - In the html.erb file as an 'arbitrary value'. This doesn't work because Tailwind classes need to be hardcoded for automatic purposes.
- In the tailwind.config.js. Doesn't work because the file has no relation to the asset pipeline at all.
I feel like 1. should be the 'intended' solution. However, I don't have enough knowledge of neither Rails nor the asset pipeline to write a PR for this. If someone provides me with pointers I can try creating a PR that makes it work.
There are two workarounds. The first is putting your images in the public/assets
folder. However that means throwing away the advantages of the asset pipeline, including fingerprinting of the images allowing long cache times. The second is maintaining a separate CSS file that is solely responsible for images. That's not ideal, because it's confusing why you would have two CSS outputs even though you're using Tailwind. And you can't use Tailwind's after:
, before:
, hover:
, etc.
StackOverflow question asking the same thing: https://stackoverflow.com/questions/66842651/inserting-a-background-image-from-asset-pipeline-with-tailwind.