buunguyen / combres

ASP.NET and MVC performance optimization library ⛺
Other
123 stars 37 forks source link

Support mixing Less and CSS in the same resource set #34

Open abepark01 opened 10 years ago

abepark01 commented 10 years ago

I have LESS resource set that I want to reference from another CSS resource set inside an ASP.NET MVC 4 web application. When I include the LESS resource set in my MVC view, the less files is compiled to CSS properly.

The issue is that LESS resourcesets don't get compiled in the outputted CSS when it's referenced from another resourceset.

The reason for the need for referencing a resourceset with less files is because a resourceset cannot have both css and less files per https://github.com/buunguyen/combres/issues/5

Here is my relevant parsts of my configuration for combres.xml

<filters>
    <filter type="Combres.Filters.FixUrlsInCssFilter, Combres" />
    <filter type="Combres.Filters.DotLessCssCombineFilter, Combres" acceptedResourceSets="siteLess" />
  </filters>
<!-- ... -->
 <resourceSet name="siteLess" type="css">
    <resource path="~/content/css/iconSetSprite.less" />
  </resourceSet>
<!-- ... -->

<resourceSet name="homeCss" type="css">
      <resource reference="siteLess" />
</resourceSet>

The less file itself has the following mixin:

.ds-icon-heart{ .ds-icon-empty-heart; }

After @Html.CombresLink("siteLess") is called in the view, the LESS gets compiled to the following CSS:

.ds-icon-heart {
  background-position: 0 -624px;
  width: 17px;
  height: 17px;
}

However, when that same LESS resource set is included in another CSS resource set the LESS the mixin does not get compiled.

After I called @Html.CombresLink("homeCss"), mixin .ds-icon-heart{ .ds-icon-empty-heart; } does not get compiled.

buunguyen commented 9 years ago

Combres doesn't support right now. It would be great if someone can take over this enhancement, I can help point to the right place.

abepark01 commented 9 years ago

Thanks for the response!

Can you outline what classes we would need to extend to support this? I would love to give it a shot.

buunguyen commented 9 years ago

As I thought more about it, it could be fairly simple. All you need to do is modifying DotLessCssFilter so that it ignores .css files. Then apply that filter for every resource set that has a mix of .less and .css files. Do you want to give this a try?

andy250 commented 9 years ago

Hey! Any updates on this? I might try adding support for this. I could use it in my project.