Bundle Config在发布模式下不起作用

时间:2018-06-25 11:35:37

标签: c# model-view-controller

我有一个.NET MVC项目。我在BundleConfig文件中管理所有.css和.js文件。 在本地调试模式下,它的工作效果非常好。但是当我运行此项目发布模式时, 用捆绑软件制作所有JavaScript文件,例如;

<script src="/bundles/alljquery?v=UzNlCXfliUxnARi00NzVdOS0lml6av0Kte2hPdkLmLw1"></script>

我在DOM中看到了这一行,但是它行不通。例如,我在一个无法正常工作的函数中编写了警报。

我在分发包中查找了示例JavaScript行,并找到了它。因此它实际上会加载文件。但是我没有看到警报或其他动作。

这是我的RegisterBundles方法;

public static void RegisterBundles(BundleCollection bundles)
        {
            #if !DEBUG
              BundleTable.EnableOptimizations = true;
            #endif
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));

            bundles.Add(new StyleBundle("~/Content/Sitecss").IncludeDirectory("~/Content/css", "*.css",true)); 

            bundles.Add(new ScriptBundle("~/bundles/alljquery").IncludeDirectory("~/Content/js", "*.js", true));

            var jsFiles = Directory.GetFiles(HttpContext.Current.Server.MapPath("/Content/Pages"), "*.js");
            foreach (var jsFile in jsFiles)
            {
                var bundleName = Path.GetFileNameWithoutExtension(jsFile);
                bundles.Add(new ScriptBundle("~/bundles/jsMrT/" + bundleName).Include(
                "~/Content/pages/" + Path.GetFileName(jsFile)));
            }


        }

我尝试这个;

BundleTable.EnableOptimizations = true;

我尝试这个;

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="BundleModule" />
        <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
    </modules>
</system.webServer>

我该如何解决?

谢谢。

2 个答案:

答案 0 :(得分:1)

添加到网络配置中。

<configuration>
   <system.web>
     <compilation debug="true" />
   </system.web>
</configuration>

答案 1 :(得分:0)

我认为所有javascript方法都是隔行扫描和重复的,因此我关闭了软件包并添加了所有脚本布局手册。这可能来自我使用的库。

相关问题