-
-
Notifications
You must be signed in to change notification settings - Fork 433
CSS background url adds '/client/ to path #887
Comments
I'm inclined to say that this is not actually a bug, and that you should just be using absolute paths in component styles. I don't think we want Sapper to have to worry about fixing paths within the styles. (And if someone did put their images in |
OK, I see, I just had no idea that I should put images in a It might be obvious if you know Express/Polka or how it the asset logic was set up but I had no idea. (Thanks for the quick answer BTW!) |
@Wolfr I don't think putting images in a The suggestion is to use absolute paths in component styles: <style>
ul {
width: 100%;
background: url('/trail.png');
}
</style>
<img src="trail.png" alt="" />
<ul>
<slot></slot>
</ul> |
Yeah, using an absolute path is probably what I would suggest here. I was thinking about #867 when I mentioned the |
Potentially relevant old issue: #420 |
I just found out that if you serve the SPA within a subfolder (as in a GitHub Pages), then an absolute path used in the CSS is not correctly resolved, even if the |
It does not work if project is hosted not from the domain root. E.g. website which exported with UPD: |
I also have the same issue as @pixeline and @artemjackson pointed out. I guess the current solution would be using a variable in the path? For example, |
The way I've got this working is to use relative or absolute paths, with relative being relative to the directory that the component is in. I.e. as if we were running on your local machine, without bundling. |
Given a new component:
And an image called trail.png (just a gray dot)
The HTML one loads but the CSS one doesn't. The image is contained in the
/static
folder.Expected behavior: both images should load.
What happens: if you inspect the CSS background URL path in the devtools, you'll see that
/client
is added to the URL. This causes a 404.The text was updated successfully, but these errors were encountered: