14

When moving from development to a production environment I have run into some problems with the way in which my javascript files are being minified. It seems that some do not minify properly, and so I have been looking around to find a way to not minify a specific bundle.

    public static void RegisterBundles(BundleCollection _bundles)
    {
        _bundles.Add(new ScriptBundle("~/bundles/toNotMinify").Include(
            "~/Scripts/xxxxxx.js"
            ));

        _bundles.Add(new ScriptBundle("~/bundles/toMinify").Include(
            "~/Scripts/yyyyy.js"
            ));
        etc..

This is the basic layout in my bundle config class. I want to find a way in which to have all of my bundles minified, apart from the first one. Is this possible? So far the only solution I have found to achieve something similar is to turn off minification globally.

2 Answers 2

13

You have a couple of options, you can either replace your use of ScriptBundle with Bundle as in this example:

_bundles.Add(new Bundle("~/bundles/toNotMinify").Include(
    "~/Scripts/xxxxxx.js"
));

.. or you could disable all transformations on a newly created bundle, like so:

var noMinify = new ScriptBundle("~/bundles/toNotMinify").Include(
    "~/Scripts/xxxxxx.js"
);
noMinify.Transforms.Clear();
_bundles.Add(noMinify);

Obviously the first solution is much prettier :)

Sign up to request clarification or add additional context in comments.

8 Comments

Rudy Sorry! I edited your response by mistake instead of mine (I left some code out by mistake and pressed on "edit" to change it. My bad ;(
Thanks. I have tried both these methods, but it still seems to minify it down when building in release mode for some reason
Rudis soln should work. If you construct a basic Bundle without specifying any transform, it will simply bundle the files as is, so this definitely should not minify your bundle.
for file 'x.js' in the bundle ensure that there is NOT a 'x.min.js' file in the folder
@stooboo why not? A normal Bundle will only include what it is given.
|
2

You just have to declare a generic Bundle object and specify the transforms you need:

var dontMinify = new Bundle("~/bundles/toNotMinify").Include(
                                        "~/Scripts/xxxxx.js");
            bundles.Add(dontMinify);

            var minify = new Bundle("~/bundles/toNotMinify").Include(
                "~/Scripts/yyyyyy.js");
            minify.Transforms.Add(new JsMinify());
            bundles.Add(minify);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.