1

I'm in the process of switching my site over to less and I was wanting to continue the use of Web.Optimization however, it fails on compiling less. Is there a way to register .less{} as the processor for this or simply tell it to bundle, but not minify anything with a .less extension?

4

1 に答える 1

1

バンドルとミニフィケーションに関するこのガイドをご覧ください。LESS ファイルをバンドルする例が含まれています。

基本的に、実装するクラスを作成しますIBundleTransform

using System.Web.Optimization;

public class LessTransform : IBundleTransform
{
    public void Process(BundleContext context, BundleResponse response)
    {
        response.Content = dotless.Core.Less.Parse(response.Content);
        response.ContentType = "text/css";
    }
}

これでCssMinify、バンドルを作成できます。

var lessBundle = new Bundle("~/My/Less").IncludeDirectory("~/My", "*.less");
lessBundle.Transforms.Add(new LessTransform());
lessBundle.Transforms.Add(new CssMinify());
bundles.Add(lessBundle);
于 2013-01-23T13:06:54.813 に答える