【发布时间】:2015-08-27 12:32:39
【问题描述】:
在我正在处理的 ASP.NET MVC 项目中,有两个与捆绑过程相关的应用程序键:AppKeys.ApplyMinifyingTransformation 显示是否应缩小和合并 .css 和 .js 文件,AppKeys.ApplyStaticFilesTransformations 显示是否应应用某些文件内容转换。这些标志的不同组合将用于不同阶段。这是RegisterBundles方法的简化版本:
public static void RegisterBundles(BundleCollection bundles)
{
BundleTable.EnableOptimizations = AppKeys.ApplyMinifyingTransformationAndBlockJs ||
AppKeys.ApplyStaticFilesTransformations;
var lessStyles = new Bundle("~/Bundles/Styles/")
.IncludeDirectory("~/Path-to-css", "*.css", true);
var postProcessors = AppKeys.ApplyStaticFilesTransformations
? new[] {new StaticFilesPostProcessor()}
: new IPostProcessor[] {};
var transformer = AppKeys.ApplyMinifyingTransformationAndBlockJs
? new StyleTransformer(new YuiCssMinifier(), postProcessors)
: new StyleTransformer(postProcessors);
transformer.CombineFilesBeforeMinification = AppKeys.ApplyMinifyingTransformationAndBlockJs;
lessStyles.Transforms.Add(transformer);
bundles.Add(lessStyles);
}
不幸的是,此代码无法按我的意愿工作。 BundleTable.EnableOptimizations 应该是 true 以使文件转换工作,但在这种情况下,文件总是合并为一个。
有没有办法明确声明我希望启用转换,但不应合并文件?
【问题讨论】:
标签: c# asp.net-mvc bundling-and-minification asp.net-bundling