【问题标题】:Error with bundling and minification捆绑和缩小错误
【发布时间】:2014-09-29 10:28:17
【问题描述】:

我知道捆绑和缩小仅在不处于调试模式时才有效。

<compilation debug="false" targetFramework="4.5"/>

如果我按 Ctrl + F5 来运行我的 SPA,它可以正常工作。

但是,如果我按 F5 启用调试,即使在 web.config 上的 debug=false 时,我的页面也无法正确加载。当我检查开发者工具时,I found this.

如果我检查我的代码和我的脚本库,它似乎没问题。

BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{
  bundles.IgnoreList.Clear();
  AddDefaultIgnorePatterns(bundles.IgnoreList);

  bundles.Add(
    new ScriptBundle("~/scripts/modernizr")
        .Include("~/scripts/modernizr-{version}.js"));

  bundles.Add(
    new ScriptBundle("~/scripts/vendor")
     .Include("~/scripts/jquery-{version}.min.js")
     .Include("~/scripts/bootstrap.min.js")
     .Include("~/scripts/knockout-{version}.js")
     .Include("~/scripts/toastr.js"));

  bundles.Add(
   new StyleBundle("~/Content/css")
     .Include("~/Content/ie10mobile.css") // Must be first. IE10 mobile viewport fix
     .Include("~/Content/bootstrap.min.css")
     .Include("~/Content/bootstrap-responsive.min.css")
     .Include("~/Content/font-awesome.min.css")
     .Include("~/Content/toastr.css")
     .Include("~/Content/styles.css")
   );
}

还有 VS 工作室的结构,files are there

如果我检查我的 index.cshtml

@using System.Web
@using System.Web.Optimization
<!DOCTYPE html>
<html>
<head>
    <title>CCJS</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
    @Styles.Render("~/Content/css")
    <script language="javascript">
        // Must be first. IE10 mobile viewport fix
        if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
            var msViewportStyle = document.createElement("style");
            var mq = "@@-ms-viewport{width:auto!important}";
            msViewportStyle.appendChild(document.createTextNode(mq));
            document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
        }
    </script>
    @Scripts.Render("~/scripts/modernizr")
</head>
    <body>
        <div id="applicationHost">
            @RenderPage("_splash.cshtml")
        </div>

        @Scripts.Render("~/scripts/vendor")
        <script src="~/Scripts/require.js" data-main="App/Main"></script>
    </body>
</html>

【问题讨论】:

    标签: c# css asp.net twitter-bootstrap visual-studio-2013


    【解决方案1】:

    您可以将此行添加到您的 BundleConfig.cs

    //note: you can map isCompressionEnabled to your webconfig appSettings
    BundleTable.EnableOptimizations = isCompressionEnabled;
    

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 2012-11-18
      • 2017-12-13
      • 2014-11-26
      • 2013-06-27
      • 2012-06-28
      • 1970-01-01
      • 2017-09-19
      • 2018-05-11
      相关资源
      最近更新 更多