How to disable Javascript/CSS minification in ASP.NET MVC 4 Beta

前端 未结 10 1331
暗喜
暗喜 2020-12-09 10:17

I am just trying out ASP.NET MVC 4 but I can\'t figure out how to disable Javascript/CSS minification feature. Especially for development environment this will help greatly

相关标签:
10条回答
  • 2020-12-09 11:08

    I think it would be right, if such feature will be available "out of the box".

    I posted a feedback on UserVoice.com: http://aspnet.uservoice.com/forums/41201-asp-net-mvc/suggestions/2702000-improve-system-web-optimization-bundle

    Give it your "voices".

    0 讨论(0)
  • 2020-12-09 11:12

    On newer versions of ASP.NET MVC just add

    #if DEBUG
                foreach (var bundle in BundleTable.Bundles)
                {
                    bundle.Transforms.Clear();
                }
    #endif
    

    right after

    BundleConfig.RegisterBundles(...);
    
    0 讨论(0)
  • 2020-12-09 11:12

    Try a new extension for System.Web.Optimization - Bundle Transformer. In Bundle Transformer implemented a number of opportunities to simplify debugging (see documentation).

    0 讨论(0)
  • 2020-12-09 11:12

    Another alternative (tested with v1.1.0.0 and MVC5):

    public class BundleConfig
    {
        public static void Register()
        {
            ScriptBundle jsBundle = new ScriptBundle("~/Scripts/myscript.min.js");
            jsBundle.Include("~/Scripts/myscript.js");
            DisableInDebugMode(jsBundle);
    
            BundleTable.Bundles.Add(jsBundle);
        }
    
        private static void DisableInDebugMode(ScriptBundle jsBundle)
        {
        #if DEBUG
            // Don't minify in debug mode
            jsBundle.Transforms.Clear();
        #endif
        }
    }
    
    0 讨论(0)
提交回复
热议问题