119

I can't believe I cannot find other questions about this, but: how does one enable bundling in debug mode? I know how it is enabled for release mode, but in debug mode I cannot find a way to enable the bundling.

Is this even possible or am I missing something?

4 Answers 4

224

You can enable this by adding

BundleTable.EnableOptimizations = true; 

in your RegisterBundles method (BundleConfig class in the App_Start folder).

check http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification for more info

You could also change your web.config:

<system.web> <compilation debug="false" /> </system.web> 

But this would disable debug mode entirely so I would recommend the first option.

Finally, to get the best of both worlds, use the #if compiler directive like this:

#if DEBUG BundleTable.EnableOptimizations = false; #else BundleTable.EnableOptimizations = true; #endif 
Sign up to request clarification or add additional context in comments.

7 Comments

I would take this a step further, and add a custom config section to your web.config (or at a minimum, an AppSetting entry.) That way, you can selectively enable/disable optimizations without having to do a rebuild.
or use #if DEBUG & #if !DEBUG precompiler statements
Also bear in mind that this overrides the debug="true" config, so optimisations are always enabled or disabled if you hardcode this value
Or use "verbose" MVC like if (HttpContext.Current.IsDebuggingEnabled) { BundleTable.EnableOptimizations = false; } else { BundleTable.EnableOptimizations = true; }
if you like the web config option you can also setup multiple web configs per configuration so debug web config would be true and release would be false learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/…
|
13

add BundleTable.EnableOptimizations = true; in Application_Start() method of Global.asax file

Comments

-3

In Global.asax add BundleConfig.RegisterBundles(BundleTable.Bundles);

 protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // add this } 

Comments

-5

The official MS site states while Debugging it's not possible to enable it. I think the reason is, that it's easier to debug while it's disabled. If you want to test the Impact on your application you have to set <compilation debug="true" /> in the Web.config

@Hebe: To Quote the MS page

It's easy to debug your JavaScript in a development environment (where the compilation Element in the Web.config file is set to debug="true" ) because the JavaScript files are not bundled or minified.

2 Comments

In my case, I merely wanted to debug the backend C# code, and due to the way our application is set up, we need bundling to work for all the stylesheets and scripts to load properly.
@Ennosuke - While it may be easier to debug, sometimes there's Javascript bugs caused by the minification process that require you to be able to run the minified scripts locally.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.