-
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
Relative data-uri option #2560
Comments
What about just providing a path variable so that a library user could adjust the path on his own when necessary? E.g.: // user code
@react-select-path: "../node_modules/react-select";
@import "@{react-select-path}/less/component.less";
// ...................................
// your code (i.e. the component.less)
@react-select-path: ".."; // default value
something {
background-image: data-uri("@{react-select-path}/images/dropdown.png");
} This is common approach to handle such things (for example 1, 2 etc.) Also see As for things like |
see less/less.js#2560 for details
And another reason to make the path customizable via variables. What if I need to replace your images with my own? Obviously I won't want to do this by replacing files in the installed node module... But if you have hardcoded |
And what if we have multiple versions of said package? I guess https://github.com/less/less-plugin-npm-import might work, but it'd be nice for this to be core IMHO. |
breaks SEMVER? |
I understand What if I use a component that uses version |
In what way? Yet again please understand that |
@seven-phases-max having just re-read that, you are right, the [wrong] impression given to me was that However (I believe), the remainder of my points remain relevant (AFAIK). Please see above post, I've since amended it. |
@seven-phases-max in terms of the issue (our discussion is slightly different), doesn't the ability to use We could continue our discussion in #2618? |
Notice that here we are talking about image files shipped with the library itself, thus whereever the package is put by the npm, the relative path of images from the corresponding less code is always the same (they all are in the same package). So There're other more generic P.S. Ah sorry, I have not see your last posts yet.
I'd rather prefer #1972, just to not repeat all those arguments stated there once more. But well, it does not really matter. |
@seven-phases-max see my continued comments in #2618. |
I would advise relative urls for any non simple project.. The only advantage of non relative is when your file is included from a mixin in a different file - less then works out the path relative to the mixin, not the source of the string. |
Apologies if I've missed the mark with this one - the documentation doesn't actually explain the path resolution behaviour so I'm guessing a bit.
From what I can tell, the
data-uri(...)
function will find files relative to the entry less file's location on disk. This makes sense, it's similar to howurl(...)
will point to a location relative to the css file that ends up being loaded in the browser, regardless of whether the less code was in another directory (e.g an include).I'm developing a component that can be used across multiple projects, published on npm + bower. Providing assets in components is tricky, so I am hoping to use the
data-uri
feature to inline image resources (i.e icons) for the component.Anyone using the component can include my component's less file in their project's stylesheet like this:
This has a lot of other benefits (developers can override the theme variables, etc.)
However, in this scenario
data-uri
breaks because I can't know the relative path from their LESS file to my bundled static images (which are provided innode_modules/react-select/images
).If there were a way to use a relative data-uri function (where the path is relative to the less file being processed and not the entry point) then bundling the component would be as simple as adding the line above, and my component's less could inline the images like
So it could either be a function that lets me access the current directory of the less file and build the URL from that (like node's
__dirname
variable) or it could more simply be an argument / different function name. some examples:I personally think that the
relative-data-uri
function name is clearest, but really anything that lets me achieve this would be brilliant!The text was updated successfully, but these errors were encountered: