We're using System.Web.Optimization bundling to bundle & compress our JS and CSS.

We also use a custom IBundleTransform implementation in addition to to the existing JsMinify and CssMinify to do some fancy stuff to the JS (replacement of certain placeholders) before sending it to the browser.

Everything works fine as long as we're running in Release mode, because then the bundling and optimizing kicks in. But in Debug mode (which is nice for debugging ;) it seems to completely ignore all the specified IBundleTransform (makes sense in most use-cases, I guess).

Is there any way to always run our own IBundleTransform, even in Debug mode, but run the other (default) bundling algorithms (JsMinify, CssMinify) only when I really want to optimize (in Release mode)?

有帮助吗?

解决方案

So the debug/release magic is controlled via the Scripts/Styles helpers. The behavior to not apply any transforms is baked into the implementation of these helpers, so if you want to do this, the best workaround might just be to have a debug/release version of each bundle and always enable bundling via BundleTable.EnableOptimizations = true.

其他提示

if (!HttpContext.Current.IsDebuggingEnabled)
    BundleTable.EnableOptimizations = true;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top