.LESS together with Razor

后端 未结 3 1576
故里飘歌
故里飘歌 2020-12-28 10:20

Is it possible to use Razor View Engine (ASP.NET MVC) together with .LESS (similar to SASS - http://lesscss.org/ for .NET), since they\'re both using \"@blah\"?

Wha

3条回答
  •  抹茶落季
    2020-12-28 11:08

    You should consider using Justin Etheredge's SquishIt library. Not only does it include the dotlesscss library, it will combine and minify your CSS and Javascript with ease!

    • Blog post regarding SquishIt
    • Source code on GitHub

    Here's an example of how I use SquishIt in Razor.

    The following code will combine, minify and LESSify all the CSS files referenced into one CSS file. It will do the same with the Javascript files.

    @MvcHtmlString.Create(
      SquishIt.Framework.Bundle.Css()
        .Add("~/media/css/reset.css")
        .Add("~/media/css/style.less")
        .Add("~/media/css/handheld.css")
        .Render("~/media/css/combined_#.css"))
    
    @MvcHtmlString.Create(
      SquishIt.Framework.Bundle.JavaScript()
        .Add("~/media/js/geo.js")
        .Add("~/media/js/jquery-1.4.4.js")
        .Add("~/media/js/jquery.unobtrusive-ajax.js")
        .Add("~/media/js/jquery.validate.js")
        .Add("~/media/js/jquery.validate.unobtrusive.js")
        .Render("~/media/js/combined_#.js"))
    

    Output looks like this:

    
    
    

    UPDATE (Over 1 year later)...
    Another project you might want to look at is Cassette which pretty much does everything SquishIt does (and more).

提交回复
热议问题