I have been searching long and hard for how to find a way to preserve most of the Web.Optimization capabilities in MVC4 when using less to build my CSS. I found a post by Ben Cull that got me MOST of the way. Essentially there are a few easy steps that you need to take in order to enable this. The primary change that I made was to turn on minification if I was running in DEBUG mode vs RELEASE.\
Steps to get less transforms working with Web Optimization...
- Install the BundleTransformer.less package from nuget.
- Using this... "Install-Package BundleTransformer.Less" in the Package Manager Console
- Once this installs it will pop-up a new open file with some modifications that you need to make to the web.config of your project.
- The rest is in code and I'll post below. Some of this is from Ben Cull and some is the modifications that I have made... I'm only including my less bundle which is what I have modified. All the other bundling techniques work just fine in my situation.
I have removed all the non relevant bundles that I have enabled on the site I'm working on. Simply retain what you have add the transform variables at the start of your method and you should be good to go!