Monday, November 18, 2013

Combining ASP.NET Bundling and Minification and LESS

The ASP.NET bundling and minification framework supports frameworks like LESS but it took me some time to figure out how to use it. What’s important to understand is that although the framework supports other languages like LESS, you have to do some extra work to get this working.

One option is to add your own IBundleTransform  implementation, based on the .less NuGet package:

  • Add some LESS files to your web application(to improve the experience, install the Web Essentials).
  • Add the .less NuGet package dotless to your project.
  • Create a BundleTransform:
  • Create a bundle of LESS files with the LessTransform and the CssMinify transform. Add the following code to the RegisterBundles method in the App_Start\BundleConfig.cs file:

Another option is to use the System.Web.Optimization.Less library available through NuGet.

1 comment:

Anonymous said...

If you're using Web Essentials anyway you might as well just get the CSS file generated when saving the LESS file.