mvc4 bundler 有一个奇怪的问题,不包括扩展名为 .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”文件?
最佳答案
我最初发布的解决方案是有问题的(是一个肮脏的黑客)。正如许多评论者所指出的,调整后的行为在 Microsoft.AspNet.Web.Optimization 包中发生了变化,并且调整不再起作用。现在我无法使用 1.1.3 版的软件包重现该问题。
请参阅 System.Web.Optimization.BundleCollection 的来源(例如,您可以使用 dotPeek),以便更好地了解您将要做什么。 另请阅读 Max Shmelev's answer .
原答案:
将 .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
}
关于c# - Bundler 不包括 .min 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11980458/