You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Importing assets using css url() function does not work as expected on build.
In order to test, i have added fonts in both public (absolute path) folder and in src/assets (relative path). Neither of them work as expected.
This is my index.css file:
I don't see any problem with the build output. url(/fonts/Namian-Regular.woff2) points the dist/fonts/Namian-Regular.woff2 and url(/assets/Namian-Regular-Baaf_SnZ.woff2) points the dist/assets/Namian-Regular-Baaf_SnZ.woff2. Both of the files exists.
Would you expand on what you are expecting here?
I don't see any problem with the build output. url(/fonts/Namian-Regular.woff2) points the dist/fonts/Namian-Regular.woff2 and url(/assets/Namian-Regular-Baaf_SnZ.woff2) points the dist/assets/Namian-Regular-Baaf_SnZ.woff2. Both of the files exists. Would you expand on what you are expecting here?
The file exists, but the path to it is wrong. You can try ctrl clicking it and you are going to see that it does not work.
I don't think the path is wrong. Vite expects the output directory to be served under / by default and output is correct in that case. It's just that your editor does not support ctrl clicking on paths starting with /.
Describe the bug
I am doing
Importing assets using css
url()
function does not work as expected on build.In order to test, i have added fonts in both
public
(absolute path) folder and insrc/assets
(relative path). Neither of them work as expected.This is my
index.css
file:This is what is generated after running npm run build:
dist/assets/index-C8OGOnN2.css
(formatted for better readability)As you can see, the path was not resolved properly.
What i expect is
Vite be able to resolve paths inside css
url()
functionsWhat actually is happening is
Vite is not able do resolve paths inside css
url()
functionsReproduction
https://github.com/GustavoMelloGit/vite-mre
Steps to reproduce
npm i
npm run build
dist
folderSystem Info
System: OS: macOS 15.0.1 CPU: (8) arm64 Apple M2 Memory: 86.63 MB / 24.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.11.0 - /usr/local/bin/node npm: 10.2.4 - /usr/local/bin/npm pnpm: 9.12.2 - ~/Library/pnpm/pnpm Browsers: Chrome: 129.0.6668.101 Safari: 18.0.1
Used Package Manager
npm
Logs
Click to expand!
The text was updated successfully, but these errors were encountered: