Disabling bundling minification for specific file extension

时光总嘲笑我的痴心妄想 提交于 2019-12-11 10:17:39

问题


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);


来源:https://stackoverflow.com/questions/14417388/disabling-bundling-minification-for-specific-file-extension

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