1. 使用NuGet安装dotless
2. 在BundleConfig中配置
var less = new Bundle("~/bundles/less").Include("~/Content/less/global.less");
less.Transforms.Add(new LessTransform());
less.Transforms.Add(new CssMinify());
bundles.Add(less);
LessTransform类
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
response.Content = Less.Parse(response.Content);
response.ContentType = "text/css";
}
}
在页面上输出
@Styles.Render("~/bundles/less")
最后在WebConfig中可配置文件压缩和缓存
<dotless minifyCss="false" cache="true" web="false" />