0

私が取り組んでいる 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つに結合されます。

変換を有効にしたいが、ファイルを結合してはならないことを明示的に述べる方法はありますか?

4

1 に答える 1

0

Web.configの要素のdebug属性の値に従って、バンドルと縮小が行われます。compilation

<compilation debug="true" targetFramework="4.0"/>

有効にすると、ファイルがそのままレンダリングdebug="false"され、ファイルがバンドルおよび縮小されたときにレンダリングされます。

したがって、明示的な最適化を削除します。つまり、行を削除します

BundleTable.EnableOptimizations = AppKeys.ApplyMinifyingTransformationAndBlockJs || 
        AppKeys.ApplyStaticFilesTransformations;

アプリケーションを本番環境にデプロイするときは、debug属性の値を忘れずに変更してください。false

詳細はこちらhttp://www.asp.net/mvc/overview/performance/bundling-and-minification

于 2015-08-27T13:32:52.953 に答える