Interfaces

Project

Less

NuGet packageOwin.Framework.Less
GitHub sourceOwinFramework.Less

Home |  Readme

This middleware will handle requests for .css files. If there is a physical file with a .css extension then it will serve this file. If there is no .css file on disk but there is a .less file with the same name, then it will use dotless to compile the less file into css and send this as the response.

For this to work efficiently you should configure output caching. Without output caching the .less file will be compiled on every request.

Adding this middleware to the Owin pipeline

 builder.Register(ninject.Get<OwinFramework.Less.LessMiddleware>())
    .As("Less")
    .ConfigureWith(config, "/owinFramework/middleware/less");    
The assumes that you are using Ninject as your IoC container, and followed the getting started walkthrough. If this is not the case then you will need to adjust the code to work in your application.

Default Configuration

The configuration below is the configuration you will get by default if you do not provide a configuration for this middleware.

{
   "owinFramework": {
      "middleware": {
         "less": {
            "documentationRootUrl": "/owin/less/config",
            "rootUrl": "/styles",
            "rootDirectory": "~\\styles",
            "enabled": true,
            "analyticsEnabled": true,
            "minify": false,
            "traceLog": false
         }
      }
   }
}

Configuration notes

  • You can set the documentationRootUrl to null or empty to disable this documentation in your production environment.
  • In your production environment you probably want to turn off analytics and turn on minification.
  • If your .less file is invalid then a blank css response will not be served. In this situation you can turn on the trace logging and also turn on tracing in the Owin Framework to see the error that is preventing your .less code from compiling.

Related Projects