Click here to Skip to main content
15,867,453 members
Articles / Web Development / LESS

.LESS Web.config/DotlessConfiguration Options

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
14 Jan 2014CPOL4 min read 13.6K   2   1
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.

Introduction

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, your 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 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:

XML
<dotless>
  <plugin name="PluginClassName" assembly="PluginAssemblyName" />
</dotless>

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Canada Canada
Cindy Potvin is a software developer based in the Montreal area. At her day job, she creates web applications using the ASP.NET MVC framework and mobile applications using the Android SDK.

Comments and Discussions

 
QuestionLife saver! Pin
David Bywaters4-Sep-14 0:34
David Bywaters4-Sep-14 0:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.