好吧,在短期内,我不能让它开始工作。过滤器似乎没有自行应用。
我正试图让梳子与我的MVC 3剃须刀应用程序一起工作。除了DotLessCssFilter,我还有其他的工作要做。
文档中写着In order to apply a filter to your resource sets, you need to modify your Combres config file
我对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>它把文件和微型化结合在一起。
在我的一个文件中,我有一个简单的较少语法:
@sprite: url(/ui/styles/sprite.png);
.foo {
background-image: @sprite;
}但它似乎从来没有通过过滤器。
不知道这是MVC问题还是一般问题。
有人成功地使用了这个过滤器吗?
,算了!(编辑)
见答案
发布于 2011-09-06 06:42:30
错过了acceptedResourceSets="dotLessCss",它需要有正确的resourceSet名称,所以在我的例子中:
acceptedResourceSets="siteCss"
发布于 2012-02-19 22:01:42
除非你愿意,否则你实际上不需要有一个acceptedResourceSets。
下面是我作为POC做的一个测试项目中的一个示例Combres.xml文件(请参阅注释):
<?xml version="1.0" encoding="utf-8"?>
<combres xmlns="urn:combres">
<filters>
<!-- This filter allows relative urls to be used in Css files like in .NET; e.g. "~/MyFolder/MyPic.png"-->
<filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
<!-- This filter allows you to define variables in a CSS file and reuse them throughout the file. -->
<filter type="Combres.Filters.HandleCssVariablesFilter, Combres" />
<!-- This filter changes Combres order of ops so that common css variables can be defined in a single
file and used throughout multiple css files, instead of having to define them in each file. -->
<filter type="Combres.Filters.DotLessCssCombineFilter, Combres" />
</filters>
<resourceSets defaultDebugEnabled="false"
defaultDuration="30"
defaultIgnorePipelineWhenDebug="true"
defaultVersion="auto"
localChangeMonitorInterval="30"
remoteChangeMonitorInterval="60"
url="~/combres.axd">
<resourceSet name="siteCss" type="css">
<resource path="~/content/Variables.css" />
<resource path="~/content/Test1.css" />
<resource path="~/content/Test2.css" />
<resource path="~/content/Site.css" />
</resourceSet>
<resourceSet name="siteJs" type="js">
<resource path="~/scripts/jquery-1.7.1.min.js" />
<resource path="~/scripts/jquery-ui-1.8.17.min.js" />
<resource path="~/scripts/jquery.unobtrusive-ajax.min.js" />
<resource path="~/scripts/modernizr-1.7.min.js" />
</resourceSet>
</resourceSets>
</combres>Variables.css:
@sprite: url('~/Content/ui/styles/sprite.png');Test1.css:
.fooTest1 {背景图像:@sprite;}
Test2.css:
.fooTest2 {背景图像:@sprite;}
输出(通过Firebug .NET选项卡):
.fooTest1{background-image:url("/Content/ui/styles/sprite.png")}.fooTest2{background-image:url("/Content/ui/styles/sprite.png")}我认为在示例应用程序中,您甚至不需要注册DotLessCssFilter,而应该注册HandleCssVariablesFilter。
然后,您可以在每个css文件中定义css变量(不重用)。
但是,如果您想在多个文件中定义和共享css变量,就像我前面所做的那样,设置过滤器注册,就像一种魅力。
Buu Nguyen在梳子项目上做得很好。
https://stackoverflow.com/questions/4817893
复制相似问题