-
-
Notifications
You must be signed in to change notification settings - Fork 384
URLs in CSS should be relative to the CSS file, but can't achieve with publicPath #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
publicPath
publicPath
Why they should be relative? It is out of scope this plugin you can use minificator for this. |
Also it can potentially break code, because you can use same css (same css module) in difference places (so resolution Anyway can you provide example what you actually have and what you expected? Maybe i don't understand you correctly. |
I've pushed a branch that implements this and it's working nicely for me so far https://github.com/karlvr/mini-css-extract-plugin/tree/publicPathRelativeToSource |
@evilebottnawi Thank you so much for your quick response. As I understand it The reason I need the URLs in my CSS to be relative (and anyone using a I thought |
If this doesn’t land, perhaps an alternative would be to implement support for a function as the |
@karlvr feel free to send a PR, let's discussion with code. |
@evilebottnawi thank you, I've sent a PR with my first option—adding the If it were possible to know where the output was going to go, this could be improved to calculate the relative URL relative to the output instead of the source. Relative URLs are native/common in CSS so I do think improving relative URL support is useful / important for this loader as it outputs CSS. Shall I make a PR for a |
Can be achieved by #373, using relative paths is not safe in some cases, so we don't want to provide this options out of box |
This appears to be an ongoing and reasonably common issue. See #44.
The issue is that webpack outputs URLs relative to the context (assumed to be where the HTML is), which works fine for JS but not CSS, as urls in CSS files are resolved relative to the CSS file, while URLs in JS files are resolved relative to the HTML.
Using
publicPath
is a blunt instrument that either requires you to use an absolute path, or to use a relative path and to always output your CSS files at the same depth (e.g. setpublicPath
to../
and always output your css files intocss/
).I am preparing a simple patch for
mini-css-extract-plugin
to add an additional option which I think I'll callurlsRelativeToSource
. It dynamically adjusts thepublicPath
that it sends to downstream loaders to the relative path from the source CSS file to the root context...So if the source file is
./forum/css/main.css
thenpublicPath
is set to../../
when passed down tourl-loader
orfile-loader
or whatever is next, which means a url in your CSS that was../img/header.png
, becomes../../forum/img/header.png
. When loaded from your CSS _assuming it's output to./forum/css/main.css
, that relative URL (while containing a redundant..
andforum
) works.The assumption that is required here is that you'll output your CSS files at the same depth in the directory structure as the source file is. Hence the option is
urlsRelativeToSource
. This is because I don't think a loader knows where the output file is going, otherwise we could just make the URLs relative to the output.Is anyone interested? This fixes the issue for me... will this be useful for others and will it be acceptable as a patch? I don't want to base our workflow on a fork!!
The text was updated successfully, but these errors were encountered: