CSS full path for images
See original GitHub issueDescribe the bug
When vite is required (included from another endpoint) the reference to images in the CSS are lost cause the CSS is injected in the page.
div {
background: url(/image/demo.png)
}
When transpiled I think it would be nice to inject the full path to avoid any problem
div {
background: url(http://localhost:3000/image/demo.png)
}
Or maybe offer a configuration to set the “publicPath”
Reproduction
Start any vite template including CSS. Then load this from another endpoint. For instance I’m on http://localhost:8000 and I include
<script src="http://localhost:3000/app.js" type="module" defer></script>
System Info
vite
version: 2.0.0-beta.27- Operating System: all
- Node version: all
- Package manager (npm/yarn/pnpm) and version: all
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
How to give the background-image path in CSS?
How to give the background-image path in CSS? · change it in Firebug/Chrome and see which one shows image. – Murali Murugesan ·...
Read more >HTML File Paths - W3Schools
File paths are used when linking to external files, like: Web pages; Images; Style sheets; JavaScripts. Absolute File Paths. An absolute file path...
Read more >CSS images: url() · WebPlatform Docs
Usage is simple — you insert the path to the image you want to include in your page inside the brackets of url()...
Read more >url() - CSS: Cascading Style Sheets - MDN Web Docs
The url() CSS function is used to include a file. The parameter is an absolute URL, a relative URL, a blob URL, or...
Read more >Absolute Path for the CSS Background-Image property?!
User-1559987826 posted. How can I set up an absolute path for this code snippet: background-image: url('Images/MenuBackground.png');.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
in vite.config.js use config of
I’ve noticed the opposite problem. I have imported a component/style framework that uses an icon font via a rule like this:
When compiled those absolute urls become:
It seems the code is blindly just prepending whatever is in those
url()
declarations. I see no test for this here: https://github.com/vitejs/vite/blob/main/packages/playground/assets/css/css-url.css So it appears to be an overlooked scenario.