-
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
Custom-output-path-aware relative-URLs #2084
Comments
See existing options (http://lesscss.org/usage/#command-line-usage-rootpath) and then if it doesn't fit your criteria, explain more about what your situation is and what you want to happen. e.g. imports or normal paths? give an example of whats in your less and what you want to see in your css. |
Hello, sorry for the late response. I was busy with other stuff. In Web Essentials, we are calling less as a service to node-server: https://github.com/madskristensen/WebEssentials2013/blob/eea5cd4d82ab36c6fc7bab4e44fa123e11a3d723/EditorExtensions/Resources/server/services/srv-less.js#L52-L75. Now, given the following LESS: foo {
+ bar {
color: lime;
background-image: url('../7up-fido-dido.png');
}
} It generates: foo + bar {
color: lime;
background-image: url(../7up-fido-dido.png);
}
/*# sourceMappingURL=Site.css.map */ Now, let's consider if Also, if I add However, the expected output in the latter case should be: foo + bar {
color: lime;
background-image: url(../../../7up-fido-dido.png);
}
/*# sourceMappingURL=Site.css.map */ Is there any setting for this to generate URLs relative to target file (as opposed to input/source file)? (For this matter, we need to carry out this post-processing step, using VS' CSS AST, which is a bit expensive op). On a slightly different note, would be nice if the
Thanks in anticipation. |
If I understand it right you'll get the desired result if you set relative path for |
@seven-phases-max, unfortunately it doesn't work with: rootPath: path.dirname(path.relative(params.sourceFileName, params.targetFileName)) or rootPath: path.relative(params.sourceFileName, params.targetFileName) or rootPath: path.dirname(params.targetFileName) both in |
Hmm, it's interesting because specifying (for example)
both produce:
|
I've also tested the following minimal node script with Less 1.6.3 and 1.7.5:
and it compiles to:
P.S. Ah, @am11 Sorry I did not notice it initially, it looks like the problem in your tests is just in |
Lol, yeah that was the issue. Thanks! I had to use this: rootpath: path.dirname(path.relative(path.dirname(params.targetFileName), params.sourceFileName)).replace(/\\/g, '/') + "/" Looks bit ugly but, less expensive than the one we have! :) |
@seven-phases-max, regarding the source-map issue described above (after the horizontal-row), is there a workaround for that too? |
@am11, Sorry no idea about source maps, I guess it would make sense to create a separate ticket for that. |
I've been fixing this on the v2 branch, but my fix is in lessc, so I think you do not need v2 to get it working. for reference, that commit was c07531a for calling less programmatically, just make sure the following are set correctly. sourceMapFilename - this comes out as the filename in the css which points to the map The only complication is that sourceMapFilename (but not outputFilename) gets put through the following options sourceMapBasepath - a path to remove from all urls in the sourcemap, and the path to the sourcemap I think in v2 I am going to change it so that the sourcemap filename is not processed by the above options and they only effect the mapping of urls in the sourcemaps content. |
On a different note, it may be of interest to you that v2 plans to be a pure javascript library that talks to its environment through a set interface.. making it easier to embed in a .net assembly through a v8 interpretter |
@lukeapage, thanks for your reply and your patience. I will keep an eye on v2. 👍 We will keep using node.js to interconnect less, sass and other services in WE (as we have one set base for NPMs). |
@seven-phases-max, I have yet another test, which is failing: In @import 'test2';
@import 'less_includes/test3'; In .a {
background-image: url('../images/a.png');
} In .b {
background-image: url('../images/b.png');
} So, there are two images folders: /temp/projects/less$ node node_modules/less/bin/lessc --rootpath="../" test1.less output/style.css yields this output: .a {
background-image: url('../../images/a.png');
}
.b {
background-image: url('../../images/b.png');
} Whereas, the expected output is: .a {
background-image: url('../../images/a.png');
}
.b {
background-image: url('../images/b.png'); // <-- this
} Apparently, it doesn't account for the relevance of the location of imported source file. The requirement is: Resolve all assets paths w.r.t. output file location. @lukeapage, should I reopen this issue? :) |
@am11 use the flag |
@lukeapage, you rock!!! This worked and thank you! 😃 👍 node node_modules/less/bin/lessc --rootpath="../" --relative-urls test1.less output/style.css |
This is for Less compiler can resolve the relative path. I somehow forgot the incorporate this bit.. 😞 Related discussion: less/less.js#2084 Fixes madskristensen#1922.
I have this: // ~/project/node_modules/css-framework/less/include/variables.less
@css-framework-fonts: "../../fonts/"; // ~/project/node_modules/css-framework/less/include/fonts.less
@font-face {
src: url("@{css-framework-fonts}some-font.woff2") format("woff2");
} // ~/project/assets/less/include/variables.less
@import "../../../node_modules/css-framework/less/include/variables";
@css-framework-fonts: "../../../../assets/vendor/css-framework/fonts/"; // ~/project/assets/less/include/icon.less
.classname {
background-image: url("../../images/icons/some-icon.svg");
} With /* ~/project/style.css */
@font-face {
src: url("assets/vendor/css-framework/fonts/some-font.woff2") format("woff2");
}
.classname {
background-image: url("../images/icons/some-icon.svg");
} when this was expected: /* ~/project/style.css */
@font-face {
src: url("assets/vendor/css-framework/fonts/some-font.woff2") format("woff2");
}
.classname {
background-image: url("assets/images/icons/some-icon.svg");
} |
@stevenvachon, I ended up using via API like this: rootpath: path.dirname(
path.relative(
path.dirname(absoluteTargetFileName),
absoluteSourceFileName)
).replace(/\\/g, '/') + '/', I guess this is also applicable in gulpfile. If not then please share that file, might help spotting the issue. :) |
@am11, that produces: @font-face {
src:url("../../../../assets/vendor/css-framework/fonts/some-font.woff2") format("woff2");
}
.classname {
background-image: url("../../../images/icons/some-icon.svg");
} which is even less correct. My gulpfile wouldn't help as it's full of plugins and the actual Less.js part is very small. The important parts are mentioned in my previous comment. |
I think the problem is that |
Alright, I was under the impression that if the target and source files are given as absolute paths, and |
For now, I'm using paths relative to the project root because |
Please change
toCSS()
so it takes custom output file path and make it produce the output with correct relativeurl()
s.Currently its producing urls relative to the source less file, whereas it should incorporate the intended location of css to be generated.
The text was updated successfully, but these errors were encountered: