Stop Cassette v2 from minifying a JavaScript file

165 views Asked by At

We are using Cassette v2 to concat and minify JavaScript files in a C# ASP.NET MVC5 project.

However, one of the dependencies uses eval to invoke some functions by name, which causes an error when the pipeline minifies the bundle.

I found this SO answer about Cassette v1, but I need to configure a single bundle to not be minified in Cassette v2.

The current configuration is:

public void Configure(BundleCollection bundles)
{
    bundles.Add<ScriptBundle>("~/bundles/uicomponents", new[] { "~/Scripts/bridge/UIComponents.js" })
}

Thanks!

1

There are 1 answers

1
Alex Jarkey On

After a week of trying things only my own I was able to figure it out. You can customise the default Cassette Pipeline collection to remove the minifier by using the "customizeBundle" parameter:

        bundles.Add<ScriptBundle>("~/bundles/uicomponents", new[] { $"~/Scripts/bridge/UIComponents.js" },
            b =>
            {
                var minifyidx = b.Pipeline.IndexOf<MinifyAssets>(); //Don't want to re-minify scripts
                if (minifyidx >= 0) { b.Pipeline.RemoveAt(minifyidx); } //Remove the object from the cassette pipeline
            }
            );

Big thanks to everyone who helped answer, hopefully this saves someone else a headache!