How to add .min and .debug files in a bundle effectively

632 views Asked by At

I want to take advantage of .min and .debug versions of js and css files.

Consider this bundle for example:

 bundles.Add(
          new ScriptBundle("~/scripts/vendor")
            .Include("~/scripts/jquery-{version}.js")
            .Include("~/scripts/knockout-{version}.debug.js")
            .Include("~/scripts/knockout-{version}.min.js")
            .Include("~/scripts/knockout-{version}.js")

What is the correct mechanism to take advantage of each file. I mean how set some setting to make ASP.NET smart enough to use .min on final releases and .debug while debugging?

2

There are 2 answers

1
Nikolay Kostov On BEST ANSWER

Just use .Include("~/scripts/knockout-{version}.js") and ASP.NET will use ~/scripts/knockout-{version}.min.js in production and ~/scripts/knockout-{version}.js when debugging

0
Ezra Bailey On

You can have the bundler switch between debug and non-debug files if you group them with a wildcard. For example:

bundles.Add(
      new ScriptBundle("~/scripts/vendor")
        .Include("~/scripts/jquery-{version}.js")
        .Include("~/scripts/knockout-*")

Then include in knockout-version.debug.js and knockout-version.js in your ~/scripts/ path.

The bundler will use the debug version if you're in debug mode, or minify the non-debug version and use it if optimizations are enabled.