对于MVC4风格捆绑不使用分档 [英] Style bundling for MVC4 not using min files

查看:146
本文介绍了对于MVC4风格捆绑不使用分档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个文件:


  • a.css

  • a.min.css

  • b.css

  • b.min.css

他们加入下列方式捆绑:

  bundles.Add(新StyleBundle(〜/内容/ ACSS)。包括(〜/内容/ a.css,〜/内容/ b.css) );

在调试中所有正在运行的应用正确地呈现:

 <链接HREF =/内容/ a.css的rel =stylesheet属性/>
 <链接HREF =/内容/ b.css的rel =stylesheet属性/>

然而,在发布运行时,我有它在以下方式呈现:

 <链接HREF =?/内容/ ACSS V = mUdXE7_fXKjICzE_XteIB1Igy6TekX1QFh-BtY6fFUw1的rel =stylesheet属性/>

和里面我创始:


  

/ *缩小失败。返回unminified内容。
  (24708):运行时错误CSS1030:。需要标识符,发现


所以,我有两个问题:


  1. 为什么不根据文档联机工作?所有的信息说,它选择分钟的文件,如果可以发行版本?

  2. 如何使它根据文档的工作?


解决方案

我有,你有相同的问题,我的解决方案包含CSS / JS文件伴随着我使用的Web要点,尽量减少.min的文件。

如果我用在调试模式下束,一切都会正常工作和所有个人非最小化的文件会在我的应用程序加载。但是,如果我设置 BundleTable.EnableOptimizations = TRUE; 然后我会得到错误,因为它遇到了麻烦尽量减少我的文件

根据<α

href=\"http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification\">http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification它规定:


  

有关ASP.NET MVC 4,这意味着调试配置,文件
  的jquery-1.7.1.js将被添加到该包。在释放
  配置,jQuery的,1.7.1.min.js将增加。捆绑
  框架如下几种常见的约定,如:


  
  

发布选择.min文件时,FileX.min.js和FileX.js
  存在。选择非.min版本的调试。


我希望它只是加载了我已经最小化的文件,只是对其进行绑扎。我认为是隐含的,但在文档中缺少的,是它也将再次减少我的已经最小化的文件,这是行不通的,并在输出导致错误。

我发现<一个href=\"http://aspnetoptimization.$c$cplex.com/workitem/56\">http://aspnetoptimization.$c$cplex.com/workitem/56其中提到:


  

您只需创建一个没有捆绑跳过缩小
  变换,即不创造ScriptBundles,只是正常的捆绑。


这竟然是在回答我的问题。通过设置我的两个 ScriptBundle StyleBundle 只需键入捆绑我现在得到正确的捆绑没有最小化。

在调试,我所有的常规CSS / JSS文件indidivually加载。当我将它设置为无调试,一切都捆绑在一起,它会自动选择所有.min的文件。

I have 4 files:

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

they are added to bundle in following way:

bundles.Add(new StyleBundle("~/Content/acss").Include("~/Content/a.css", "~/Content/b.css"));

When running application in debug all is rendered properly:

 <link href="/Content/a.css" rel="stylesheet"/>
 <link href="/Content/b.css" rel="stylesheet"/>

However when running in release I have it rendered in following way:

 <link href="/Content/acss?v=mUdXE7_fXKjICzE_XteIB1Igy6TekX1QFh-BtY6fFUw1" rel="stylesheet"/>

And inside I'm founding:

/* Minification failed. Returning unminified contents. (24,708): run-time error CSS1030: Expected identifier, found '.'

So I have two questions:

  1. Why it is not working according to docs online? All information says that it chooses min file if available for release version?
  2. How to make it working according to documentation?

解决方案

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.

这篇关于对于MVC4风格捆绑不使用分档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆