代码之家  ›  专栏  ›  技术社区  ›  Murat Güzel

包配置在释放模式下不工作

  •  1
  • Murat Güzel  · 技术社区  · 6 年前

    我有一个.NET MVC项目。我管理bundleconfig文件中的所有.css和.js文件。 它在本地调试模式下工作得很好。但是当我运行这个项目发布模式时, 使所有的javascript文件与bundle类似;

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

    我在国内看到了这条线,但它不起作用。例如,我在一个不起作用的函数中编写了一个警报。

    我在包中找了一个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 回复  |  直到 6 年前
        1
  •  1
  •   Ramesh Malviya    6 年前

    添加到web配置中。

    <configuration>
       <system.web>
         <compilation debug="true" />
       </system.web>
    </configuration>
    
        2
  •  0
  •   Murat Güzel    6 年前

    我认为所有的javascript方法都是交错和重复的,所以我关闭了这个包,并添加了一个手动布局的所有脚本。