-
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
Rewrite url paths based on rewrite rules #1005
Conversation
After writing the initial note for the pull request, I changed the rewrite logic to use a generic function, rather than a set of rewrite rules. Also, it might make more sense to attach the 'rewritePaths' function to a specific tree, rather than the less global variable. |
Am doing some extensive changes re: url re-writing (being able to choose to re-map to relative or not and also specify a rootpath).. have decided to look at this for 1.4.0 if there is still a need. |
Am currently wondering if this would be better done as a user function.. Now we have 1.3.3 which has much improved control over url re-writing, I'm wondering if many people will need this feature. If they don't you could add a function to less.functions and then reference that in order to make specific path rewrites? |
Thanks for looking into this. I'm not clear on where the rewrite function would be defined. (was it in the docs? sorry if I missed it there). Do you mean I would do something like...
If that's the case it might work out. However, there could still be some arguments for making it possible to override the global url handling. For example, I currently use a customized fork of less.js to 'bundle' a set of less modules. When I do this I rewrite all urls and paths, not just urls declared with a custom function. For example, if I import a css file via a normal @import url('...'), I also want to rewrite that normal 'url()'. TL;DR: I still recommend being able to customize the global url path processing. P.S. |
@adorsk ok, for your use-case it doesn't make sense to have a function. I think you might have a point. |
Sorry this PR is now too far out of date. If you do need this functionality, I would suggest you implement a plugin that edits the url nodes - see less-plugin-inline-images which converts |
I would like to add the ability to rewrite paths based on a set of rewrite rules.
For example, I would like to do the following:
This would yield:
Use Case for This Feature
The ability to rewrite paths would make it possible to write modular CSS with less, by making it possible to annotate modules through the use of unique URIs.
For example, say I have a module 'common' that includes these files:
I want to write another module, 'moduleA', that can access these files. However, I don't know yet where the 'common' module will be located yet in relation to 'moduleA'. So what I do is I use a path identifier for 'common', like this:
Then, in my less.rewritePaths function, I can map the identifier path to the actual path when I know it: