小编典典

捆绑软件不包括.min文件

c#

我对mvc4捆绑器有一个奇怪的问题,不包括扩展名为.min.js的文件

在我的BundleConfig类中,我声明

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/Scripts/jquery")
        .Include("~/Scripts/jquery-1.8.0.js")
        .Include("~/Scripts/jquery.tmpl.min.js"));            
}

我认为

<html>
    <head>
    @Scripts.Render("~/Scripts/jquery")
    </head><body>test</body>
</html>

而当它渲染时,它只会渲染

<html>
    <head>
         <script src="/Scripts/jquery-1.8.0.js"></script>
    </head>
    <body>test</body>
</html>

如果我将jquery.tmpl.min.js重命名为jquery.tmpl.js(并相应地更新捆绑软件中的路径),则两个脚本都将正确呈现。

是否有一些配置设置导致其忽略“ .min.js”文件?


阅读 176

收藏
2020-05-19

共1个答案

小编典典

我最初发布的解决方案是有问题的(很脏)。正如许多评论者所指出的那样,Microsoft.AspNet.Web.Optimization包中的调整行为已更改,并且该调整不再起作用。目前,该软件包的版本1.1.3根本无法重现该问题。

请参阅System.Web.Optimization.BundleCollection的资源(例如,您可以使用dotPeek)以更好地了解您将要做什么。另请阅读Max
Shmelev的答案

原始答案

将.min.js重命名为.js或执行类似的操作

    public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
    {
        if (ignoreList == null)
            throw new ArgumentNullException("ignoreList");
        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);
    }

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.IgnoreList.Clear();
        AddDefaultIgnorePatterns(bundles.IgnoreList);
        //NOTE: it's bundles.DirectoryFilter in Microsoft.AspNet.Web.Optimization.1.1.3 and not bundles.IgnoreList

        //...your code
     }
2020-05-19