-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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 moduleUrl
option
#2615
add moduleUrl
option
#2615
Conversation
Could you elaborate? Because by default (i.e. without Aside of above it would be extremely useful to provide some example of a practical use-case this option is intended to cover. |
This is the current behavior: @import "folder/file.less"; /* folder/file.less */
.a { background: url(img.png); } Result without relative-urls: .a { background: url(img.png); } Result with relative-urls: .a { background: url(folder/img.png); } That's fine for normal CSS. But with CSS Modules /* folder/file.less */
.a { background: url(./img.png); }
.b { background: url(module/img.png); } should result in .a { background: url(./folder/img.png); }
.b { background: url(module/img.png); } But currently it results in: (with relative-urls) .a { background: url(folder/img.png); }
.b { background: url(folder/module/img.png); } With this PR (with relative-urls plus module-url): .a { background: url(./folder/img.png); }
.b { background: url(module/img.png); } The original problem was that |
In other words, the purpose of this feature is to always interpreter path starting with Then, hmm, I'd rather suggest a slightly different solution. Instead of an option hardcoded as a back-patch for the
e.g. for your use-case (and for many others) you'd use just that option w/o Theoretically I would even suggest even more radical solution. Instead of using P.S. #2560 reminds me that all those |
I could change the
|
this make sense, but let's wait for other opinions... |
Any word on this? I'm eagerly awaiting the result of this PR 😊 |
@markdalgleish Well, not until there're more opinions and there's some consensus of how exactly it should be solved (since it's several ways with their pros and cons). |
I think including it in the IMO the fact that the output URLs are specifically designed for CSS Modules—always starting with a |
I'm in agreement with this. It seems unlikely to break anything, since writing It seems fine to make it default because the workaround, if someone HAD been intentionally writing |
So does this mean that if .a { background: url(./folder/img.png); }
.b { background: url(module/img.png); } ...would be emitted as-is, without the URLs being rewritten by Less? |
emitted as-is is not enough.
|
@sokra Yes, @seven-phases-max is talking about current behavior. The proposed behavior is as you say, that a What about doing this:
"modules" would apply the folder-relative rewriting when the That way, we don't get too much option bloat, and it would reduce the confusion between relative-urls and module url rewriting. Basically, these are all just URL rewriting rules (or "modes"), and it doesn't make sense to have two options for URL rewriting that you have to use in some special combination. That would also allow for future expansion if there was a different type of rewriting needed, such as relative to node_modules folder, or whatever it might be (like --rewrite-urls=node). What do you think? |
@matthew-dean that sounds great to me 👍 |
@matthew-dean sorry for the nudge, but has there been any movement on this? |
@seven-phases-max Are you on board? |
+1. My only objection is the word "module(s)". It does not have any direct connection to |
I'm currently on vacation... |
Any update on this PR? |
I think we need some better keywords a la @seven-phases-max's suggestions. I'm not familiar enough this usage to suggest anything. |
Still broken. Common. It's 2016! |
@mmakarin Would you like to update and make a new PR? |
I think, In the webpack environment, we usually need to distinguish between relative urls/imports and "module" urls/imports. That's why we had to introduce the special Tbh: I think |
Reminder on this thread. A PR would be merged once #2615 (comment) and #2615 (comment) are addressed. @sokra can you modify the original PR? Or does someone want to create a new PR with these fixes? |
@matthew-dean @seven-phases-max I would be up to implement this I'd follow @matthew-dean 's suggestion:
Should this be done on the current 3.0.0 branch? Would it be ok then to just replace |
@jhnns Go for it! And yes, it's fine on the 3.0 branch. I'm still working through the 3.0 checklist. |
done(). Please review #3041 😁 I also renamed |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This PR adds an option which allows to switch the mode for
relativeUrls
.By default
url(./file)
is emitted asurl(file)
andurl(module/path)
is emitted asurl(folder/module/path)
when imported from another file infolder
.With
moduleUrl = true
url(./file)
is emitted asurl(./file)
andurl(module/path)
is emitted asurl(module/path)
even when imported from another file.Why? CSS Modules use CommonJs-like
url(...)
s.