私が取り組んでいる ASP.NET MVC プロジェクトには、バンドル プロセスに関連する 2 つのアプリケーション キー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
ありますが、その場合、ファイルは常に1つに結合されます。
変換を有効にしたいが、ファイルを結合してはならないことを明示的に述べる方法はありますか?