7
votes

Running in debug from VS 2013.2RTM Pro, MVC 5.1 app.

If the compilation mode is set to debug="true" it is supposed to disable Bundling and minification but it does not. When I examine the View source on a page the styles and scripts are bundled.
<script src="/bundles/modernizr?v=K-FFpFNtIXjnmlQamnX3qHX_A5r984M2xbAgcuEm38iv41"></script>

If I set BundleTable.EnableOptimizations = false; in the BundleConfig.cs it does disable Bundling and minification but that is not how it is supposed to work. I shouldn't have to remember to toggle the EnableOptimizations setting!

Things are working properly in VS 2012 MVC 4 apps.

Is this a MVC 5.1 bug? Has anyone else had this problem? Is there a way to get debug to disable the Bundling and minification?

web.config:

  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" useFullyQualifiedRedirectUrl="true" maxRequestLength="100000" enableVersionHeader="false" />
    <sessionState cookieName="My_SessionId" />
  <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
  </system.web>

_Layout.cshtml:

In header

@Styles.Render("~/Content/css") @Styles.Render("~/Content/themes/base/css") @Scripts.Render("~/bundles/modernizr")

At end of body

@Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jqueryui") @Scripts.Render("~/bundles/jqueryval")

2
Also having this problemJason
@Jason check my answer belowRady

2 Answers

1
votes

You may have a look at this article http://codemares.blogspot.com.eg/2012/03/disable-minification-with-mvc-4-bundles.html

or you can use this simple implementation

public class NoMinifyTransform : JsMinify
{
    public override void Process(BundleContext context, BundleResponse response)
    {
        context.EnableOptimizations = false;
        var enableInstrumentation = context.EnableInstrumentation;
        context.EnableInstrumentation = true;
        base.Process(context, response);
        context.EnableInstrumentation = enableInstrumentation;
    }
}

and then when defining your script bundles in (App_Start) you can use the base Bundle class like this

            IBundleTransform jsTransformer;
#if DEBUG
            BundleTable.EnableOptimizations = false;
            jsTransformer = new NoMinifyTransform();
#else
            jstransformer = new JsMinify();
#endif
            bundles.Add(new Bundle("~/TestBundle/alljs", jsTransformer)
               .Include("~/Scripts/a.js")
                .Include("~/Scripts/b.js")
                .Include("~/Scripts/c.js"));
0
votes

I'm seeing this as well in the release version. To get around it, I'm using conditional flags to achieve the same effect.

        BundleTable.EnableOptimizations = true;

#if DEBUG
        BundleTable.EnableOptimizations = false;
#endif