禁用特定文件扩展名的捆绑压缩 [英] Disabling bundling minification for specific file extension

查看:109
本文介绍了禁用特定文件扩展名的捆绑压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将站点切换到更少,而我想继续使用Web.Optimization,但是,它在编译时失败.有没有办法将.less{}注册为处理器,或者只是告诉它捆绑,但不缩小任何带有.less扩展名的东西?

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?

推荐答案

看看本指南

Take a look at this guide to bundling and minification. It contains an example on bundling LESS files.

基本上,您创建一个实现IBundleTransform

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";
    }
}

使用此版本和CssMinify,然后可以创建捆绑包.

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

这篇关于禁用特定文件扩展名的捆绑压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆