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

前端 未结 10 1350
暗喜
暗喜 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:07

    Rather than replace instances of JsMinify and CssMinify, one can instead use interfaces. This option was not available in earlier releases because the second constructor parameter was a type rather than an interface.

    IBundleTransform jsTransform;
    IBundleTransform cssTransform;
    
    #if DEBUG
        jsTransform = new NoTransform("text/javascript");
        cssTransform = new NoTransform("text/css");
    #else
        jsTransform = new JsMinify();
        cssTransform = new CssMinify();
    #endif
    
    Bundle jsBundle = new Bundle("~/JsB", jsTransform);
    Bundle cssBundle = new Bundle("~/CssB", cssTransform);
    

    Perhaps also worth noting, for scripts that are shipped with minified and non-minified versions e.g. jQuery, one can use a helper method to optionally strip out the ".min" for DEBUG builds to facilitate debugging:

    private string Min(string scriptNameIncludingMin)
    {
    #if DEBUG
        return scriptNameIncludingMin.Replace(".min", ""); // Remove .min from debug builds
    #else
        return scriptNameIncludingMin;
    #endif
    }
    
    // ...
    jsBundle.AddFile(Min("~/Scripts/jquery-1.7.2.min.js"));
    

提交回复
热议问题