Skip to content

Latest commit

 

History

History
80 lines (54 loc) · 1.75 KB

using-less.md

File metadata and controls

80 lines (54 loc) · 1.75 KB
title
Server-side Usage

Less can be used on the command line via npm, downloaded as a script file for the browser or used in a wide variety of third party tools.

Installation

The easiest way to install Less on the server, is via npm, the node.js package manager, as so:

$ npm install -g less

Command-line Usage

Once installed, you can invoke the compiler from the command-line, as such:

$ lessc styles.less

This will output the compiled CSS to stdout. To save the CSS result to a file of your choice use:

$ lessc styles.less styles.css

To output minified CSS you can use the clean-css plugin. When the plugin is installed, a minified CSS output is specified with --clean-css option:

$ lessc --clean-css styles.less styles.min.css

To see all the command line options run lessc without parameters or see Usage.

Usage in Code

You can invoke the compiler from node, as such:

var less = require('less');

less.render('.class { width: (1 + 1) }', function (e, output) {
  console.log(output.css);
});

which will output

.class {
  width: 2;
}

Configuration

You may pass some options to the compiler:

var less = require('less');

less.render('.class { width: (1 + 1) }',
    {
      paths: ['.', './lib'],  // Specify search paths for @import directives
      filename: 'style.less', // Specify a filename, for better error messages
      compress: true          // Minify CSS output
    },
    function (e, output) {
       console.log(output.css);
    });

See Usage for more information.

Third Party Tools

See the Tools section for details of other tools.