【发布时间】:2015-12-06 01:30:58
【问题描述】:
我正在开发一个 asp.net mvc-5 Web 应用程序。我有以下脚本和 css 文件包如下:-
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.min.js",
"~/Scripts/tm-scripts.js",
"~/Scripts/activeMenuItem.js",
"~/Scripts/respond.js"
));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
// "~/Content/style.css",
"~/Content/touchTouch.css",
"~/fonts/font-awesome.css"));
现在我定义脚本和 css 的方式将导致脚本按字母顺序排列,而我希望脚本根据添加的方式进行排序。现在从我自己的阅读和搜索中我发现我可以使用IBundleOrderer. ro 定义订单。但正如这个问题所示link 似乎有两种方法可以使用IEnumerable<BundleFile> 或IEnumerable<FileInfo> 来实现这个,所以我需要遵循哪种方法?
第一种方法:-
class NonOrderingBundleOrderer : IBundleOrderer
{
public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)
{
return files;
}
}
或者第二种方法:-
class NonOrderingBundleOrderer : IBundleOrderer
{
public IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)
{
return files;
}
}
【问题讨论】:
-
实际上,您提供的链接描述了何时应用“排序”(如果/当您使用通配符时)。还有另一个命令occurs for "known libraries" this post describes,所以在你做任何事情之前,看看它是否适用于你。嗯……
-
@EdSF 对不起,我没有明白你的意思,现在如果我不实现 IBundleOrderer,那么即使我不使用通配符,即使我不使用通配符,我也不能 100% 保证脚本的顺序使用 .Include ,我将脚本一一包含在包中。因为默认捆绑包可能会为某些脚本提供最高优先级。所以为了避免这种行为,我必须实现我自己的 IBundleOrderer ,所以我的问题是我应该使用 IEnumerable
还是 IEnumerable ?
标签: asp.net asp.net-mvc razor asp.net-mvc-5