在我正在处理的 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
为了文件转换工作,但在这种情况下,文件总是合并为一个。
有没有办法明确声明我希望启用转换,但不应合并文件?