2014-06-13 35 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文件,以防止替代