不要缩小ASP .NET MVC 4 BundleConfig中的某些文件

Léo*_*sne 19 asp.net-mvc bundle asp.net-mvc-4 asp.net-optimization

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

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"
    ));

...
Run Code Online (Sandbox Code Playgroud)

为了缩小它,我当然使用:

BundleTable.EnableOptimizations = true;
Run Code Online (Sandbox Code Playgroud)

所以它很棒.

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

任何帮助将不胜感激.

Dav*_*bec 20

使用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);
Run Code Online (Sandbox Code Playgroud)

您还必须从目录中删除.min.js文件以防止替换


小智 5

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

@{
    BundleTable.EnableOptimizations = false;
 }

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

@{
    BundleTable.EnableOptimizations = true;
}
Run Code Online (Sandbox Code Playgroud)

  • 线程安全性= 0.即第1页渲染其他一些包,第二页是渲染布局.结果是第1页也将获得一个未分类的包. (4认同)

Léo*_*sne 4

我不知道问题出在哪里,但我尝试:

  • 只是捆绑,而不是缩小。这不起作用。

    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"
        ));
    
    Run Code Online (Sandbox Code Playgroud)
  • 覆盖 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">
Run Code Online (Sandbox Code Playgroud)

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