As documented in recent posts, I’ve been tinkering getting the LESS and CoffeeScript compilers running on Windows Script Host. I’ve now got round to wrapping these up as ASP.NET HTTP Handlers so you can easily use them in ASP.NET-based websites. You simply reference the *.less and *.coffee files and they get served up as CSS and JavaScript directly. For example:
<link href="content/style.less" rel="stylesheet"> <script src="content/site.coffee"></script>
No need to install add-ins into Visual Studio or add build steps to your project. The main downside is that it won’t run on non-Windows platforms under Mono (although I’m tempted adapt it to use Mozilla’s SpiderMonkey JavaScript Shell).
If you’re running Visual Studio 2010 then simply use the LessCoffee NuGet package.
PM> Install-Package LessCoffee
If you’re using Visual Studio 2008 you’ll need follow these manual steps:
- Copy LessCoffee.dll to your web application’s /bin directory
- Add the following entries to your web.config file:
<system.web> <httpHandlers> <add path="*.coffee" type="DotSmart.CoffeeScriptHandler, LessCoffee" verb="*" validate="false"/> <add path="*.less" type="DotSmart.LessCssHandler, LessCoffee" verb="*" validate="false"/> </httpHandlers> </system.web> <!-- IIS 7 --> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <handlers> <add path="*.coffee" type="DotSmart.CoffeeScriptHandler, LessCoffee" verb="*" name="DotSmart.CoffeeScriptHandler"/> <add path="*.less" type="DotSmart.LessCssHandler, LessCoffee" verb="*" name="DotSmart.LessCssHandler"/> </handlers> </system.webServer>
If you’re using Windows 2003/IIS 6 then you will need to map the file extensions *.less and *.coffee to aspnet_isapi.dll.
The source is on GitHub, obv: https://github.com/duncansmart/LessCoffee