Style bundling for MVC4 not using min files

前端 未结 3 1961
失恋的感觉
失恋的感觉 2020-12-28 20:03

I have 4 files:

  • a.css
  • a.min.css
  • b.css
  • b.min.css

they are added to bundle in following way:

bundles.Ad         


        
相关标签:
3条回答
  • 2020-12-28 20:36

    Your actual question is not answerable because it is already acting as documentation states (which is why I asked what documentation you were looking it, but you have chosen to ignore my comment).

    If you want to keep the same behavior in release mode, use BundleTable.EnableOptimizations = false; in your Global.asax. This will turn off the bundling and minification that is active in debug mode only. Then to use your own minified css / js files, simply point your bundles path to the minified versions.

    According to documentation, you could also use "~/Content/a{version}.css" which would use non-minified version in debug mode and minified version for release. However, I have not tried that.

    0 讨论(0)
  • 2020-12-28 20:42

    I had the exact same issue you had, my solution contained css/js files accompanied by their .min files that I had used Web Essentials to minimize.

    If I used the bundles in debug mode, everything would work correctly and all of the individual non-minimized files would be loaded in my app. However, if I set BundleTable.EnableOptimizations = true; then I would get errors because it had trouble minimizing my files.

    Based on http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification where it states:

    For ASP.NET MVC 4, this means with a debug configuration, the file jquery-1.7.1.js will be added to the bundle. In a release configuration, jquery-1.7.1.min.js will be added. The bundling framework follows several common conventions such as:

    Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist. Selecting the non “.min” version for debug.

    I expected it to simply load up my already minimized files and just bundle them. What I believe is implied, but missing in the documentation, is that it will also again minimize my already minimized files, which wasn't working and causing errors in the output.

    I found http://aspnetoptimization.codeplex.com/workitem/56 which mentions:

    You can skip minification simply by creating bundles with no transform, i.e. don't create ScriptBundles, just normal Bundles.

    This turned out to be the answer to my issue. By setting both my ScriptBundle and StyleBundle to just type Bundle, I now get the correct bundling without the minimizing.

    In debug, all of my regular css/jss files are loaded indidivually. When I set it to non-debug, everything is bundled and it automatically chooses all of the .min files.

    0 讨论(0)
  • 2020-12-28 20:43

    Have you looked a Bundle Transformer, it's 1.6.5 version introduced a property called usePreMinifiedFiles which enables/disables usage of pre-minified files.

    Have you set BundleTable.EnableOptimizations = true;

    From the documentation

    Note: Unless EnableOptimizations is true or the debug attribute in the compilation Element in the Web.config file is set to false, files will not be bundled or minified. Additionally, the .min version of files will not be used, the full debug versions will be selected. EnableOptimizations overrides the debug attribute in the compilation Element in the Web.config file

    0 讨论(0)
提交回复
热议问题