简体   繁体   English

ASP.NET MVC 4 ScriptBundle返回空

[英]ASP.NET MVC 4 ScriptBundle returns empty

Specifically, I am trying to create a ScriptBundle in MVC 4 with already minified scripts, and return this same Bundle whether the project is in Debug or not. 具体来说,我正在尝试使用已经缩小的脚本在MVC 4中创建ScriptBundle,并返回相同的Bundle,无论项目是否在Debug中。

My web project references the MVC Telerik Grid NuGet package. 我的Web项目引用了MVC Telerik Grid NuGet包。 In that package, Telerik only provides the minified JS files. 在该软件包中,Telerik仅提供缩小的JS文件。 Bundling code is below. 捆绑代码如下。

        // telerik scripts
        bundles.Add(new ScriptBundle("~/scripts/bundles/telerik").Include(
            "~/Scripts/2012.1.214/telerik.common.min.js",
            "~/Scripts/2012.1.214/telerik.textbox.min.js",
            "~/Scripts/2012.1.214/telerik.calendar.min.js",
            "~/Scripts/2012.1.214/telerik.datepicker.min.js",
            "~/Scripts/2012.1.214/telerik.grid.min.js",
            "~/Scripts/2012.1.214/telerik.grid.filtering.min.js"));

Other ScriptBundles run fine, but when my project attempts to reference this bundle, the request appears as: scripts/bundles/telerik?v= Returning nothing. 其他ScriptBundles运行正常,但是当我的项目尝试引用此包时,请求显示为: scripts/bundles/telerik?v=什么都不返回。

If I set BundleTable.EnableOptimizations = true , then it DOES return the ScriptBundle and references a specific version, however this solution is unacceptable. 如果我设置BundleTable.EnableOptimizations = true ,那么它会返回ScriptBundle并引用特定版本,但是这个解决方案是不可接受的。

I do not want to forcibly set BundleTable.EnableOptimizations = true , since I want all other Bundles to return the non-minified versions when appropriate. 我不想强行设置BundleTable.EnableOptimizations = true ,因为我希望所有其他Bundles在适当的时候返回非缩小版本。

Anyone have a similar experience and if so, what was the solution? 任何人都有类似的经历,如果有,解决方案是什么?

I think you have the same problem, please look at this link: mvc4 bundler not including .min files 我想你有同样的问题,请看这个链接: mvc4 bundler不包括.min文件

Either rename .min.js to .js or do something like: 将.min.js重命名为.js或执行以下操作:

    public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
    {
        if (ignoreList == null)
            throw new ArgumentNullException("ignoreList");

        ignoreList.Clear();

        ignoreList.Ignore("*.intellisense.js");
        ignoreList.Ignore("*-vsdoc.js");
        ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
        //ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
        ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM