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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Take a look at this guide to bundling and minification. It contains an example on bundling LESS files.
Essentially you create a class that implements 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";
}
}
With this and CssMinify
you can then create a bundle.
var lessBundle = new Bundle("~/My/Less").IncludeDirectory("~/My", "*.less");
lessBundle.Transforms.Add(new LessTransform());
lessBundle.Transforms.Add(new CssMinify());
bundles.Add(lessBundle);