ecomfe / est

EFE Styling Toolkit based on Less
http://ecomfe.github.io/est
MIT License
397 stars 70 forks source link

img-replace的使用问题 #15

Closed otakustay closed 10 years ago

otakustay commented 10 years ago

根据 https://github.com/ecomfe/est/blob/master/src/typography.less#L124img-replace默认使用了url()格式,所以我现在有这样的情况:

.my-class { .img-replace("../img/abc.png"); }

最后编译后,会变成相对于est所在目录的地址,而不是定义.my-class的css所在目录为基准

不太懂less,可能是由于编译时用了啥参数还是因为加了冒号导致的,正确的用法应该是啥?

zmmbreeze commented 10 years ago

我用node编译试了下,路径正常。你是不是指定了--relative-urls参数。这会修改url地址

otakustay commented 10 years ago

嗯,没错的话edp-build是默认有这参数的,为了一堆less合在一起@import到一具main.less的时候图片地址还是正确的……结果mixin就会被坑到

补一下:https://github.com/ecomfe/edp-build/blob/master/lib/processor/less-compiler.js#L58

otakustay commented 10 years ago

对于这个问题,我在想less是不是支持搞成这样:

.my-class { .img-replace(url(../img/abc.png)); }

这样会不会跟着我自己的less文件走?如果会的话是不是能加上.img-replace-naked之类的

Justineo commented 10 years ago

似乎所有用到 url() 的地方都有这个问题耶。

otakustay commented 10 years ago

是啊,基本上全有这问题,我们这边的.linear-gradient-with-background-image也是这问题,不知道有没有只求办法绕过去解决的?我想把多个less给@import到一起是个比较常见的手段,因此--relative-urls开头也经常是开着的,这种情况下mixin的实用价值很惨

Justineo commented 10 years ago

@otakustay 有一个方法是把 mixin 里面输出 url 的部分全部替换成 ~"url(@{img-url})",这样就是你写啥我输出啥。