Asp.Net Bundle - How to raise exception when minification fails -


i'm using asp.net mvc 5 , bundling , minification system system.web.optimization 1.1.0.0:

        bundles.add(new scriptbundle("~/angularlibraries").include(             ......             )); 

and render bundle:

@scripts.render("~/angularlibraries") 

from time time manually check state of bundles opening corresponding url in browser, , find them errors. example:

/* minification failed. returning unminified contents. (262,145-152): run-time error js1019: can't have 'break' outside of loop: break (40,297-304): run-time error js1019: can't have 'break' outside of loop: break  */ 

because bundling mechanism returns unminified contents when minification fails, i'm unaware of error until manually open bundle in browser.

how can setup bundling system raise exception when minification fails can aware of error?

found solution. have created custom class derives scriptbundle , overrides method applytransforms:

public class customscriptbundle : scriptbundle {     public customscriptbundle(string virtualpath)         : base(virtualpath)     {     }      public customscriptbundle(string virtualpath, string cdnpath)         : base(virtualpath, cdnpath)     {     }      public override bundleresponse applytransforms(bundlecontext context, string bundlecontent, ienumerable<bundlefile> bundlefiles)     {         bundleresponse bundleresponse = base.applytransforms(context, bundlecontent, bundlefiles);          if (bundleresponse.content.startswith("/* minification failed. returning unminified contents."))             exceptionmanager.logmessage("minification failed following bundle: " + context.bundlevirtualpath);          return bundleresponse;     } } 

i ended logging message (an receiving email notification elmah) , not throwing exception because have minification enabled default on production, , app continue working ok anyway.

if throw exception, you'll see this:

enter image description here

this solution applicable stylebundle.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -