Enable bundling and minification in debug mode in ASP.NET MVC 4

前端 未结 4 1694
梦谈多话
梦谈多话 2020-12-07 13:25

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

相关标签:
4条回答
  • 2020-12-07 13:58

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

    0 讨论(0)
  • 2020-12-07 14:13

    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
            }
    
    0 讨论(0)
  • 2020-12-07 14:15

    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.

    0 讨论(0)
  • 2020-12-07 14:22

    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
    
    0 讨论(0)
提交回复
热议问题