15

When I run my ASP.NET MVC 4 app in release mode, the bundles are still outputting the unminified and separate js files, instead of bundling and minifying it into fewer bundled JavaScript files.

Any ideas?

FYI, release config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>
Bart Verkoeijen
  • 16,545
  • 7
  • 52
  • 56
FutuToad
  • 2,750
  • 5
  • 36
  • 63

4 Answers4

38

Thanks to aleyush's comment that Web.release.config is only used during publishing the app, and not when running it locally, I was able to fix it by adding the following lines to the BundleConfig.cs file:

#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif

Since Debug mode will define the DEBUG constant, and during Release mode it is not defined, this line will only execute during Release mode. (you can test it by setting a breakpoint)

Bart Verkoeijen
  • 16,545
  • 7
  • 52
  • 56
2
  1. Nothing is being bundled or minified if debug is set to true in Web.config file so that you can easily debug the output.

  2. If you want to override this, just add the following line of code to your BundleConfig file:

    BundleTable.EnableOptimizations = true;

aleyush
  • 644
  • 1
  • 6
  • 19
  • the debug attribute is set to false: RemoveAttributes(debug) – FutuToad Mar 02 '13 at 22:53
  • 6
    Web.release.config is used only when you publish your web site. http://blogs.msdn.com/b/webdev/archive/2010/10/26/asp-net-web-projects-web-debug-config-amp-web-release-config.aspx – aleyush Mar 04 '13 at 07:57
0

This worked for me

<system.web>
    <compilation debug="false" />
</system.web>
Abhinav Gujjar
  • 2,570
  • 2
  • 25
  • 35
0

My bundle was too big. I had to break it down into smaller parts and it worked fine. Maybe some variable conflicted after minification.

Put this line at end of your bundleconfig only for test...

BundleTable.EnableOptimizations = true;

If you open the minified file, you will see something like this.

    /* Minification failed. Returning unminified contents.
    (5079,1-2): run-time warning JS1195: Expected expression: .
    (5080,18-19): run-time warning JS1004: Expected ';': :
    (5084,18-19): run-time warning JS1004: Expected ';': :
    (5091,18-19): run-time warning JS1004: Expected ';': :
    (5095,20-21): run-time warning JS1197: Too many errors. The file might not be a JavaScript file: ;
.....

Breaking down you bundle, you can isolate the issue.

Hope this may help someone.

Thalles Noce
  • 791
  • 1
  • 9
  • 20