3

In my project, I want to send application settings to the browser from the server.

To do so, I have created a class named "ConfigFileTransform", that inherits from IBundleTransform. In the process method, I replace keywords in javascript by their values. (Maybe it is not the best solution...)

For example, the query limit for a type of object is set to the client using this transform class.

My problem comes when I debug my application, I see the debugger going to my custom bundle transform class, but the rendered javascript does not contain the replacements...

In release mode, everything is ok.

Does anyone know what I can do to see my transforms applied when I am in debug mode?

Julien
  • 903
  • 7
  • 12

1 Answers1

5

Put this in the Application_Start method in your Global.asax file.

BundleTable.EnableOptimizations = true;

I haven't worked with only applying certain transforms but taking a look at this post:

ASP.Net MVC Bundles and Minification

You should be able to do this. You might need to refactor your bundle code a little so that you can add Conditional Compilation Variables to clear your transforms in debug only. So it could look something like this:

var noMinify = new ScriptBundle("~/bundles/toNotMinify").Include(
    "~/Scripts/xxxxxx.js"
);
#if DEBUG
    noMinify.Transforms.Clear();
    noMinify.Transforms.Add(new ConfigFileTransform())
#endif

_bundles.Add(noMinify);
Community
  • 1
  • 1
DSlagle
  • 1,563
  • 12
  • 19
  • Thanks for your answer. The problem is that this setting turns on bundling and minification too. The debugging of javascript will become very hard. Is there possible to just activate my custom transform? – Julien Jun 10 '13 at 19:13
  • Thanks, I tweak a little your sample because of my multiple bundles but it works. – Julien Jun 11 '13 at 08:57