-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
Add Option To Fix Relative Urls #124
Conversation
Your patch has a definetely better quality than my, great work! |
I tend to agree. What's the point of having an option that basically means "don't be broken"? On the other hand, I can see how people would be squeamish about mucking up their css with regex, so I figured that opt-in would give the PR a better shot. I'm happy to remove the option or make it opt-out. |
postcss actually parses css via regexp, so, if anyone don't like regexp, he shouldn't use css-loader at all. |
Any update on this PR getting merged or not? :) |
+1 any update? |
👍 This works like a charm. |
+1 for this fix |
It's good solution for #96 Thank you!! |
Any maintainers here? Please let this land |
Thank you so much for this! |
I just spent 3 hours debugging this exact issue and would absolutely have loved this option. |
This really deserves merging. Fixes the issue well. |
This PR has no labels, no comments from the Webpack team, and subsequently no visibility into when a fix of this nature might make it into style-loader. Would really appreciate comment, @sokra et al, please and thank you! I and another coworker spent a few hours trying to debug this problem. |
This PR has gotten +1s from so many people, and no code-commit has been made to this repo in almost 9 months. It's sad that a package used by almost every user of webpack - the base loader for almost every css/sass/less/style-related loader - has gone unmaintained like this for this long, with multiple viable and useful fixes sitting in PRs, especially this one. |
I'll put it on my TODO list. style-loader will be one of the things I'll care about after my vacation... |
@sokra My sincere thanks for your reply! Please enjoy your vacation 🏖 |
Made some modifications to support URLs with hashes and id references (common on SVGs). |
Edit: Ignore my previous derp. @bendytree and @romulof's forks are both great though for the issue in question 👍 |
@samhh, can you post your CSS/Sass/whatever input, CSS output, base URL and webpack publicUrl? |
@romulof I knew it was going to be something obvious I was cocking up... and it was... there was an issue with the font itself. My apologies! Keep up the great work :-) |
@sokra hope you had a great vacation. Any news on whether this will be merged or not? |
@sokra Are there any current workarounds that you would recommend? |
What the status of this? |
@sokra might be busy with webpack 2 release. |
If it helps, I'm using |
As much as I like this PR I think there might be a better solution. I did a little digging around and saw that @sokra added styles differently when source maps were enabled because, at the time, I believe source maps didn't work when referred inside a style tag (his comment here: #30 (comment)) This bug was fixed in Chromium in early 2015 and has likely made it to Chrome by now: https://bugs.chromium.org/p/chromium/issues/detail?id=456062 So I think the best solution at this point would be removing the link element + Blob-based object url approach from style-loader. @sokra thoughts? I'd be willing to work on a PR. |
Ok, I've spent hours and came up with a conclusion. This PR is the best solution at this time for style-loader (if @bendytree merges in @romulof's bug fix to support urls with hash fragments) . However, once Chrome Canary 57.0.2981.0's functionality makes it into latest Chrome, we won't need this PR and could simplify how style-loader adds styles and source map and it will all just work, relative urls and all (I made these changes in #165). style-loader would only need to add the styles and sourceMappingURL directive directly in a style element as text. Chrome Canary is paying attention to changes in style elements and will load a new source map if you provide a sourceMappingURL directive. I'm going to submit a separate PR that'll work in the near future. Here's a summary of my findings as I went about trying to implement an alternative solution:
|
@sokra Can you please chime in now and make a decision to accept or reject this PR? We've waited 8 months and several of us are moving to forks. How would you like to address this issue? Do you believe this feature should be part of style-loader? If not, what would you recommend instead? Please also consider #165 as an alternative (might be more appropriate for the future). |
Fix sourcemap and css background images bug See: webpack-contrib#124
@john-bai Thank you for your progress on this issue. @SpaceK33z @sokra or @TheLarkInn This seems to be the most discussed PR on style-loader. It looks like @john-bai put really a lot of effort to investigate in this issue. Maybe you can give him or someone else push rights or something like that to get some more help reviewing/maintaining? :) |
What is the status of this? We've stopped upgrading |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.) Rebase in current master please.
2.) If you need something addressed use @webpack-contrib/org-maintainers
so you are pinging the right people.
3.) Between this #165 we have a fix & a future proof feature. I'm personally leaning towards landing this sooner than later as a patch to solve current pains and including #165 in the next Major as it is still pending on browser support.
//cc @bebraw @ekulabuhov
It looks like someone else is going to have to take this on. @bendytree hasn't been around since the original PR a year ago |
@sontek - Thanks for the heads up, i'll get it taken care of. |
I pulled down his changes and rebased them on master as #186 |
Closing this in favor of #186 |
When sourceMaps are enabled, relative urls stop working. This appears to be a pain point for a lot of people. (Ref 1, 2, 3, 4, 5, 6, 7, 8, 9, etc)
Basically
style-loader
uses a link data-uri to embed the css with a source map. That means relative urls have no way to resolve their path.Ideally urls should be converted to absolute urls before the
style-loader
runs, but that isn't always possible. In my opinionstyle-loader
is in a unique position to alleviate this issue.This pull request creates an opt-in option
fixUrls
. When enabled, it uses regex to replace relative image/font urls with absolute urls according to the page location.Ideally I'd parse the css, but client-side parsers look to be 40-80KB and would likely be a lot slower. Parsing has to happen client side because the location is not known until then.
I've included about 30 test (which can be run with
npm test
) to verify that relative urls are resolved properly, absolute urls are not touched, etc.