Combres 和 DotLessCssFilter
好吧,短期内我无法让它发挥作用。该过滤器似乎无法自行应用。
我正在尝试让梳子与我的 MVC 3 剃须刀应用程序一起使用。除了 DotLessCssFilter 之外,我已经完成了所有工作。
在文档中它说为了将过滤器应用于您的资源集,您需要修改您的Combres配置文件
我已经修改了combres.config,如下所示:
<combres xmlns='urn:combres'>
<filters>
<filter type="Combres.Filters.DotLessCssFilter, Combres" acceptedResourceSets="dotLessCss" />
</filters>
<resourceSets url="~/combres.axd" defaultDuration="30" defaultVersion="1" defaultVersionGenerator="Combres.VersionGenerators.Sha512VersionGenerator">
<resourceSet name="siteCss" type="css">
<resource path="~/UI/Styles/1140.css" />
<resource path="~/UI/Styles/typeimg.css" />
<resource path="~/UI/Styles/layout.css" />
</resourceSet>
<resourceSet name="siteJs" type="js">
<resource path="~/UI/Scripts/opt/util.js" />
<resource path="~/UI/Scripts/opt/core.js" />
</resourceSet>
</resourceSets>
</combres>
它组合了文件并缩小为它应该。
在我的一个文件中,我有一个简单的 less-syntax:
@sprite: url(/ui/styles/sprite.png);
.foo {
background-image: @sprite;
}
但它似乎从未通过过滤器。
不知道这是 MVC 问题还是一般问题。
有人成功使用过这个过滤器吗?
没关系! (编辑)
查看答案
Well in short term I can't get it to work. The filter doesn't seem to apply it self.
I'm trying to get combres to work with my MVC 3 razor application. And I've got everything to work except the DotLessCssFilter.
In the documentation it says In order to apply a filter to your resource sets, you need to modify your Combres config file
I've modified the combres.config like this:
<combres xmlns='urn:combres'>
<filters>
<filter type="Combres.Filters.DotLessCssFilter, Combres" acceptedResourceSets="dotLessCss" />
</filters>
<resourceSets url="~/combres.axd" defaultDuration="30" defaultVersion="1" defaultVersionGenerator="Combres.VersionGenerators.Sha512VersionGenerator">
<resourceSet name="siteCss" type="css">
<resource path="~/UI/Styles/1140.css" />
<resource path="~/UI/Styles/typeimg.css" />
<resource path="~/UI/Styles/layout.css" />
</resourceSet>
<resourceSet name="siteJs" type="js">
<resource path="~/UI/Scripts/opt/util.js" />
<resource path="~/UI/Scripts/opt/core.js" />
</resourceSet>
</resourceSets>
</combres>
And it combines the files and minifies as it should.
In one of my files I have a simple less-syntax:
@sprite: url(/ui/styles/sprite.png);
.foo {
background-image: @sprite;
}
But it seems that it's never put through the filter.
Don't know if this is a MVC problem or a general one.
Anyone used this filter successfully?
Never mind! (EDIT)
See answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错过了
acceptedResourceSets="dotLessCss"
它需要有正确的资源集名称,所以在我的例子中:acceptedResourceSets="siteCss"
Missed the
acceptedResourceSets="dotLessCss"
it need to have the proper resourceSet name so in my case:acceptedResourceSets="siteCss"
除非您愿意,否则您实际上并不需要拥有 AcceptedResourceSets。
以下是我作为 POC 所做的测试项目中的示例 Combres.xml 文件(请参阅注释):
Variables.css:
Test1.css:
Test2.css:
.fooTest2 {background-image: @sprite;}
输出(通过 Firebug .NET 选项卡):
我认为在您的示例应用程序中,您甚至不需要注册 DotLessCssFilter 而应该只注册 HandleCssVariablesFilter。
然后,您可以在每个 css 文件中定义 css 变量(不重复使用)。
但是,如果您想在多个文件之间定义和共享 css 变量,请像我上面那样设置过滤器注册,效果就像一个魅力。
Buu Nguyen 在 Combres 项目上做得非常出色。
You don't actually need to have an acceptedResourceSets unless you want to.
Here is a sample Combres.xml file from a test project I did as a POC (see comments):
Variables.css:
Test1.css:
Test2.css:
.fooTest2 {background-image: @sprite;}
Output (via Firebug .NET tab):
I would argue that in your sample app, you don't even need to register the DotLessCssFilter and instead should just register the HandleCssVariablesFilter.
You could then define css variables in each of your css files (no reuse).
But if you want to define and share css variables among multiple files, set up the filter registration as I did above, works like a charm.
Buu Nguyen has done a great job on the Combres project.