打捆不包括.min文件 [英] Bundler not including .min files

查看:183
本文介绍了打捆不包括.min文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与mvc4打捆不包括带扩展名的文件.min.js一个奇怪的问题。

I have a weird issue with the mvc4 bundler not including files with extension .min.js

在我BundleConfig类,我宣布

In my BundleConfig class, I declare

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>

而当它呈现,只呈现

And when it renders, it only renders

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

如果我重新命名为jquery.tmpl.min.js jquery.tmpl.js(和更新相应的束的路径),这两个脚本被正确渲染。

If I rename the jquery.tmpl.min.js to jquery.tmpl.js (and update the path in the bundle accordingly), both scripts are rendered correctly.

有一些配置设置,导致它忽略.min.js文件?

Is there some config setting that is causing it to ignore '.min.js' files?

推荐答案

我最初发布的解决方案是有问题的(是一个肮脏的黑客)。该调整行为Microsoft.AspNet.Web.Optimization包已更改,并且好办法不工作了,正如许多评论者指出。现在我不能带包的版本1.1.3重现问题都没有。

The solution I originally posted is questionable (is a dirty hack). The tweaked behaviour has changed in Microsoft.AspNet.Web.Optimization package and the tweak does not work anymore, as pointed out by many commenters. Right now I cannot reproduce the issue at all with the version 1.1.3 of the package.

请参阅System.Web.Optimization.BundleCollection源(可以使用 dotPeek 为例)为更好地了解什么你即将做的。
另请阅读最大什梅廖夫的回答

Please see sources of System.Web.Optimization.BundleCollection (you can use dotPeek for example) for better understanding of what you are about to do. Also read Max Shmelev's answer.

原来的答复

要么重新命名为.min.js或.js文件做这样的事情。

Either rename .min.js to .js or do something like

    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
     }

这篇关于打捆不包括.min文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆