-
I am having trouble figuring out how to succeed referencing local images in css, in a I am using vite-ruby/vite-rails with rails. Can anyone provide a working example? Where is a good place to put local images? Do I need to somehow register them (or the directory they are in), so that vite will know to build and serve them? Or, wait... am I supposed to put them all in If this is documented somewhere I'm missing, feel free to link me! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Whenever an asset is referenced using Nothing special is required for referencing images inside CSS files, but I highly recommend using the default import aliases or your own import aliases to reference them: .background {
background-image: url('@/images/bg.png');
} The reason I recommend using aliases, and the On the other hand, if you want to reference assets using tag helpers, Vite needs to know that it should process them somehow. A good location to place images is <%= vite_image_tag 'images/logo.jpg' %> See this section for an in-depth explanation. |
Beta Was this translation helpful? Give feedback.
Whenever an asset is referenced using
url
in CSS or imported from JS, Vite will fingerprint it and include it in the build.Nothing special is required for referencing images inside CSS files, but I highly recommend using the default import aliases or your own import aliases to reference them:
The reason I recommend using aliases, and the
@
prefix in particular, is that it works across pre-processors, and Vite will always detect and transform it correctly.On the other hand, if you want to reference assets using tag helpers, Vite needs to know that it should process them somehow.
A good location to place images is
app/frontend/i…