Skip to content

images referenced in CSS? #321

Answered by ElMassimo
jrochkind asked this question in Q&A
Discussion options

You must be logged in to vote

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:

.background {
  background-image: url('@/images/bg.png');
}

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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jrochkind
Comment options

Answer selected by jrochkind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants