2014-06-13 30 views
15

我不想缩小我在ASP .NET MVC 4解决方案中使用的所有文件。因此,例如我有这在我的BundleConfig.cs:不要缩小ASP .NET MVC 4中的某些文件BundleConfig

bundles.Add(new StyleBundle("~/CSS/bootstrap").Include(
    "~/Content/Bootstrap/body.css", 
    "~/Content/Bootstrap/bootstrap-responsive.css", 
    "~/Content/Bootstrap/bootstrap-mvc-validation.css", 
    "~/Content/Bootstrap/bootstrap-theme.css", 
    "~/Content/Bootstrap/bootstrap.css" 
    )); 

... 

而且来缩小它,当然我用:

BundleTable.EnableOptimizations = true; 

所以它的伟大工程。

但现在,我怎么能缩小除了一个包之外的所有文件?我遇到了一个删除一些CSS类并希望不能缩小这个CSS的类的问题。

任何帮助将不胜感激。

+0

如果您重命名文件'xxxxx.min.css'它仍然尝试缩小它? – mxmissile

+0

谢谢你的回答,但我更喜欢不这样做,当我更新Bootstrap时,我不想移动和重命名文件。 –

回答

3

我不知道问题出在哪里来自,但我想:

  • 只是捆绑,不运行如下。它不起作用。

    bundles.Add(new Bundle("~/CSS/bootstrap").Include(
        "~/Content/Bootstrap/body.css", 
        "~/Content/Bootstrap/bootstrap-responsive.css", 
        "~/Content/Bootstrap/bootstrap-mvc-validation.css", 
        "~/Content/Bootstrap/bootstrap-theme.css", 
        "~/Content/Bootstrap/bootstrap.css" 
        )); 
    
  • 覆盖UI错误。它可以工作,但它只是一个临时补丁。

最后,我决定使用标准的CSS调用(并提出一些意见,为什么在代码解释):

<link rel="stylesheet" href="/Content/Bootstrap/body.css"> 
<link rel="stylesheet" href="/Content/Bootstrap/bootstrap-responsive.css"> 
<link rel="stylesheet" href="/Content/Bootstrap/bootstrap-mvc-validation.css"> 
<link rel="stylesheet" href="/Content/Bootstrap/bootstrap-theme.css"> 
<link rel="stylesheet" href="/Content/Bootstrap/bootstrap.css"> 

如果你有更好的想法,请告诉我们! :)

5

我有一个类似的问题。解决方案是禁用并启用视图中的缩小。例如

@{ 
    BundleTable.EnableOptimizations = false; 
} 

@Styles.Render("~/layout") 
@RenderSection("CSS", false) 

@{ 
    BundleTable.EnableOptimizations = true; 
} 
+3

线程安全性= 0.即第1页呈现其他一个包,其中一个第二页呈现布局。结果是第1页也会得到一个未分类的包。 – John

14

使用Transforms.Clear()跳过缩小,但保持文件捆绑

//declare bundle 
var bundle = new ScriptBundle("~/javascripts/ckEditor") 
       .Include("~/Scripts/ckeditor/ckeditor.js") 
       .Include("~/Scripts/ckeditor/config.js"); 

//skip transformation. Result is that files are only bundled, but not minified. 
bundle.Transforms.Clear(); 

bundles.Add(bundle); 

您也可以从目录中排除.min.js文件,以防止替代