Julien
Julien

Reputation: 913

How to apply bundle transform in debug mode?

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?

Upvotes: 3

Views: 3377

Answers (1)

DSlagle
DSlagle

Reputation: 1583

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

Upvotes: 5

Related Questions