ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
764 stars 113 forks source link

Enable/Disable bundling based on preprocessor #288

Closed ashu66867 closed 3 months ago

ashu66867 commented 11 months ago

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?

osjoberg commented 8 months ago

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