2

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?

mehrandvd
  • 8,806
  • 12
  • 64
  • 111

2 Answers2

3

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

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
2

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.

Ezra Bailey
  • 1,434
  • 13
  • 25