本文介绍了阻止Cassette缩小JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用盒式磁带来缩小我的JavaScript.我不希望Cassette缩小我的JavaScript文件之一,因为它会导致错误.我宁愿使用原始库作者提供的已经缩小的版本.

I'm using Cassette to minify my JavaScript. I don't want Cassette to minify one of my JavaScript files because it's causing an error. I'd rather use the already minified version provided by the original library authors.

如何在不缩小文件的情况下将JavaScript文件添加到Cassette?

How can I add a JavaScript file to Cassette without it minifying the file?

推荐答案

您可以对Cassette 1.x使用以下代码来创建不执行任何缩小操作的IAssetTransformer

You can use the following code for Cassette 1.x to create a IAssetTransformer that doesn't perform any minification

public class NoMinification : IAssetTransformer
{
    public NoMinification() {}

    public Func<Stream> Transform(Func<Stream> openSourceStream, IAsset asset)
    {
        return openSourceStream;
    }
}

然后更新您的CassetteConfiguration来将已经缩小的文件放入它自己的捆绑包中,因为您必须在单个捆绑包中为所有文件设置缩小器.如果此javascript文件具有对另一个文件的依赖关系,该依赖关系将由卡匣最小化并最终位于其自己的捆绑包中,则可以使用.AddReference,如我在注释行中所示.

And then update your CassetteConfiguration to put the already minified file it's own bundle, because you have to set the minifier for all of the files in a single bundle. If this javascript file has a dependency on another file, which will minified by cassette and end up in it's own bundle, you can use .AddReference as I show in the commented out line.

public class CassetteConfiguration : ICassetteConfiguration
{
    public void Configure(BundleCollection bundles, CassetteSettings settings)
    {
        //So, we set a no-op minifier for this bundle and force it into it's own bundle.
        bundles.Add<ScriptBundle>("Scripts/already-minified-file.min.js", b => {
            b.Processor = new ScriptPipeline { Minifier = new NoMinification() };
            //b.AddReference("~/Scripts/dependent-scripts.js");
        });
    }
}

这篇关于阻止Cassette缩小JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 10:36