c# - BundleConfig.cs 使用 bootstrap.min.css

标签 c# css asp.net-mvc twitter-bootstrap

我的 BundleConfig.cs 文件如下所示 (CSS):

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css",
                  "~/Content/bootstrap-switch.css",
                  "~/Content/datepicker.css",
                  "~/Content/bootstrap-duallistbox.css",
                  "~/Content/fullcalender.css",
                  "~/Content/fullcalender.print.css"));
        BundleTable.EnableOptimizations = true;

没有我在哪里调用 bootstrap.min.css,然而,当我只更新 bootstrap.css 文件时,我的任何更改都没有被识别。我开始在 .min 文件中进行更改,然后我注意到了我的更改。

我知道 BundleTable.EnableOptimizations = true; 获取所有 .css 文件并将它们最小化,但我不明白为什么我必须更新 .min 文件才能识别我的风格改变了。

我希望 bootstrap.css 文件在内存中最小化并以这种方式使用。

有人可以解释为什么会这样吗?

只是为了了解更多信息,我在 VS2013 中使用 MVC5

最佳答案

当您将 stylesheet.css 包含在一个包中并且您的元素中已经有一个 stylesheet.min.css 文件时,优化框架将使用 .min 文件,当 BundleTable.EnableOptimizations == true 时。

它对 script.min.js 文件做同样的事情。

BundleTable.EnableOptimizations = true; // when this is not false
bundles.Add(new StyleBundle("~/Content/css").Include(
    "~/Content/bootstrap.css", // will look for bootstrap.min.css
    "~/Content/site.css", // will look for site.min.css
    "~/Content/bootstrap-switch.css", // will look for bootstrap-switch.min.css
    "~/Content/datepicker.css", // will look for datepicker.min.css
    "~/Content/bootstrap-duallistbox.css", // will look for bootstrap-duallistbox.min.css
    "~/Content/fullcalender.css", // will look for fullcalender.min.css
    "~/Content/fullcalender.print.css")); // will look for fullcalender.print.min.css

如果您希望优化框架为您缩小,只需从您的元素中删除 bootstrap.min.css。

From the docs :

public static void RegisterBundles(BundleCollection bundles)
{
     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));
         // Code removed for clarity.
}

前面的代码创建了一个名为 ~/bundles/jquery 的新 JavaScript 包,其中包括 Scripts 文件夹中与通配符字符串“~/Scripts/jquery -{版本}.js”。对于 ASP.NET MVC 4,这意味着使用调试配置,文件 jquery-1.7.1.js 将被添加到包中。在发布配置中,将添加 jquery-1.7.1.min.js。捆绑框架遵循几个常见的约定,例如:

  • 当“FileX.min.js”和“FileX.js”存在时选择“.min”文件发布。
  • 选择非“.min”版本进行调试。
  • 忽略仅由 IntelliSense 使用的“-vsdoc”文件(例如 jquery-1.7.1-vsdoc.js)。

关于c# - BundleConfig.cs 使用 bootstrap.min.css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28323489/

相关文章:

html - 将 CSS 应用到带有类的 div 内的所有元素是级联的还是显式的?

asp.net-mvc - 在 autofac 中使用命名注册与 MVC Controller 注入(inject)集成

c# - UWP/C# 中的图像散列,图像在缩放和灰度化后水平重复

c# - 如何使用 Web API 返回文件?

c# - Firebase 流式 REST 连接是否计入并发连接限制?

html - 光标位置在标签后没有到达正确的位置

html - 我应该在哪里实现 "viewport"(HTML、CSS 或两者)?

c# - Linq 基于多个字段标记列表中的重复项

c# - 在 MVC、C# 中的每个请求中运行一个方法?

asp.net - 为 asp.net mvc 应用程序创建链接