11

我在编译的文件中遇到了 LESS 破坏相对 URL 的问题。例如,我有;

├── style.less
├── style.css
├── assets
│   ├── img
│   │   └──  bg.png
│   ├── less
│   │   └──  included.less

Style.less 导入included.less,其中包含以下行;

body {background: url(../img/wall-texture.png);}

但是 style.css 中的输出变成了

body {background: url(assets/less/assets/less/../img/wall-texture.png);}

这里发生了什么,我该如何解决这个问题,以便在编译后我的路径保持正确?我意识到也许我在included.less 中的相对路径需要调整,这很好,但是目前,随着“资产/更少”的加倍减少,在保持合理文件夹结构的同时获得正确的路径变得非常复杂。除此之外,我使用 git 子模块来包含不同的 LESS 项目,所以我真的不想更改 less 文件中的代码或文件夹结构,我只想强制 LESS 正确编译。(我已经尝试了所有我能找到的 Windows 编译器,它们的行为都一样。)

非常感谢任何帮助!

4

2 回答 2

2

很可能有一个解决方案可以解决您的编译问题。如果不是,一种可能的解决方案(确实需要您更改 LESS 文件)是插入路径。这样,编译器可能会不理会它,只要附加到它:

body {background: url(~"../img/wall-texture.png");}
于 2013-01-28T13:37:48.447 回答
1

Have a look at https://github.com/marklagendijk/WinLess/issues/12 It seems to be related with exactly the version you are using (1.5.3). I recommend to update to the latest winless build which is already 1.8.0.

There have been several issues with relative paths along the way of winless. But most of them seem to be fixed. See also https://github.com/marklagendijk/WinLess/issues/search?q=path

Please note that the default behavior of the less compiler is actual to retain the relative path as you would expect.

于 2013-01-29T08:21:09.717 回答