WebOptimizer icon indicating copy to clipboard operation
WebOptimizer copied to clipboard

Enable/Disable bundling based on preprocessor

Open ashu66867 opened this issue 2 years ago • 1 comments

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?

ashu66867 avatar Oct 18 '23 15:10 ashu66867

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;
    });

osjoberg avatar Jan 31 '24 12:01 osjoberg