.LESS Web.config/DotlessConfiguration options

Many options of the .LESS CSS parser can be set directly from the Web.config file, but many of them are not clearly described. Here is my attempt to document them :

lessSource

Sets the name of the file reader class to use (must implement the dotless.Core.Input.IFileReader interface). Default value is dotless.Core.Input.FileReader.

minifyOutput

Indicates if the CSS produced by the .LESS parser should be minified afterwards. You may wish to minify the files for performance reasons, but if you already use the System.Web.Optimization framework for minification you can leave it off.  Default value is false.

debug

Sets the debug mode that prints comments in the console output. Default value is false.

cacheEnabled

Indicates if the CSS generated from the LESS file should be cached for 7 days by the web browser by setting the HTTP headers, otherwise the CSS file will always be reloaded by the browser. Default value is true.

web

Indicates if .LESS is running in a web application or from the command line. Depending on the rest of the configuration and the custom logger or file reader you may have used, you web application may work correctly even if the web mode is off. Default value is false.

mapPathsToWeb

When .LESS is running as a web application, indicates if the paths should be mapped to the location of the website. Otherwise, the paths are relative to to the current directory to allow files outside the web directory structure. Default value is true.

sessionMode

Dotless does not need the session but it may be enabled with this option to use the session in plugins. The possible values are Enabled, QueryParam (see next section) and Disabled, and the default value is Disabled.

sessionQueryParamName

When the sessionMode is QueryParam, a parameter must be added to the query string so the session can be used. The name of the parameter can be specified using this option, and the default value is sstate.

logger

Sets the name of the logger to use to log parsing errors (must implement the dotless.Core.Loggers.ILogger interface). It does not work with the Web.config as of .LESS version 1.3.1, but it can be set manually from the DotlessConfiguration object. Default value is null, but two loggers are available : the dotless.Core.Loggers.ConsoleLogger that logs to the Visual Studio console output and the dotless.Core.Loggers.DiagnosticsLogger that logs to the trace listeners used by the current application.

logLevel

Sets the level at which the parser errors are logged. The possible values are Info, Debug, Warn and Error, and the default value is Error. Please note that no logger is set by default.

optimization

.LESS optimizes the parsing of the .LESS file by separating it into chunks and parsing each chunk instead of the whole file at once. If the value is 0, the operation is not optimized, and if the value is larger than 0 the optimization is used. Default value is 1.

plugins

Contains the list of .LESS plugins used by the application. Plugins are used to add new functions to .LESS and are created as classes implementing the IFunctionPlugin interface.By default, no plugins are added. To add a plugin :


  

disableUrlRewriting

Indicates if the urls in the imported files should be adjusted depending on the location of the LESS file importing it. Default value is false.

inlineCssFiles

Indicates that when the file imported by the @import directive is a CSS file,  the content of the files should be put in directly in output without trying to parse it as a LESS file instead of keeping the import directive. Default value is false.

importAllFilesAsLess

Indicates if all imported files should be processed as LESS files even if they end with the .css extension, otherwise only the .less files are processed as LESS. Default value is false.

handleWebCompression

Indicates if .LESS should handle the compression of the response according to the Accept-Encoding header of the request, otherwise it is not compressed and may be compressed by setting IIS options (the same response should not be compressed twice,). The options gzip, deflate and identity are supported for the Accept-Encoding header. The default value is true and the default encoding used is gzip if no compatible compression method is found in the header.

disableParameters

Indicates if the parameters for the query string should be ignored by .LESS, or if the parameters should be defined as a variable inside the LESS file requested by the ParameterDecorator. For example, if parameters are enabled, style.less?param=value will be added as @param: value; in the LESS file (the value should be URL encoded). Default value is false.

disableVariableRedefines

Indicates that variables being redefined should be disabled, so less will search from the bottom to the top of the file. This is used to make .LESS behave like Less.js when handling variables. Default value is false.

keepFirstSpecialComment

Indicates that the first comment starting by /** in the LESS file should be kept even after minification. Default value is false.

 

If you need to use options that do not work from the Web.config, the Less.Parse method can take a DotlessConfiguration object as a parameter. In my case, I already use System.Web.Optimization for minification and bundling of the CSS files, so I created my own bundle transformation class that implements the IBundleTransform interface and calls the parser.