Stop Cassette from minifying a JavaScript file

无人久伴 提交于 2019-12-11 03:33:11

问题


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.

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


回答1:


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

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


来源:https://stackoverflow.com/questions/12980458/stop-cassette-from-minifying-a-javascript-file

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