.LESS together with Razor

匆匆过客 提交于 2019-11-30 04:18:28

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!

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:

<link rel="stylesheet" type="text/css" href="/media/css/combined_312454.css" />
<script type="text/javascript" href="/media/js/combined_312454.js"></script>

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

LESS and the Razor engine are not related.

If you are interested in using LESS, check out dotlesscss. See its Git repository and wiki. For some reason, its main website is down since august and they haven't brought it back up.

.NET 4.5 and MVC 4 now has this out of the box

http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!