WebOptimizer
WebOptimizer copied to clipboard
Enable/Disable bundling based on preprocessor
Is it possible to disable the bundling for DEBUG mode and enable it for RELEASE mode?
I am migrating a .Net framework project, which has the below: #if DEBUG BundleTable.EnableOptimizations = false; #else BundleTable.EnableOptimizations = true; #endif }
Does WebOptimizer have any option or settings to do similar stuff?
Given that you configure AddWebbOptimizer with a pipeline and that you are using the included taghelpers to "render" the bundle just change EnableTagHelperBundling appropriately like this:
#if DEBUG
var useWebOptimizer = false;
#else
var useWebOptimizer = true;
#endif
services.AddWebOptimizer(
pipeline =>
{
pipeline.AddJavaScriptBundle("/bundles/js","/scripts/a.js","/scripts/b.js");
pipeline.AddCssBundle("/bundles/css","/scripts/a.css","/scripts/b.css");
},
option =>
{
option.EnableCaching = true;
option.EnableTagHelperBundling = useWebOptimizer;
});