LESS - Command Line Usage

Using the command line, we can compile the .less file to .css.
The following command is used to install lessc with npm(node package manager) to make the lessc available globally.
npm install less -g

You can also add a specific version after the package name. For example npm install less@1.6.2 -g
The following command is used to install the latest version of lessc in your project folder.
npm i less -save-dev

It is also added to the devDependencies in your project package.json.
It is tagged as beta when the lessc structure is published to npm Here, the new functionality is developed periodically. less -v is used to get the current version.
The commit - ish is to be specified, when we proceed to install an unpublished version of lessc and the instructions need to be followed for identifying a git URL as a dependency. This will ensure that you are using the correct version of leesc for your project.
bin/lessc includes binary in the repository. It works with Windows, OS X and nodejs on *nix.
Input is read from stdin when source is set to dash or hyphen(-).
lessc [option option = parameter ...]  [destination]
For instance, we can compile .less to .css by using the following command −
lessc stylesheet.less stylesheet.css

We can compile .less to .css by and minify the result using the following command.
lessc -x stylesheet.less stylesheet.css

Following table lists out options used in command line usage −
Help
Help message is displayed with the options available.
lessc -help
lessc -h

Include Paths
It includes the available paths to the library. These paths can be referenced simply and relatively in the Less files. The paths in windows are separated by colon(:) or semicolon(;).
lessc --include-path = PATH1;PATH2

Makefile
It generates a makefile import dependencies list to stdout as output.
lessc -M
lessc --depends

No Color
It disables colorized output.
lessc --no-color

No IE Compatibility
It disables IE compatibility checks.
lessc --no-ie-compat

Disable Javascript
It disables the javascript in less files.
lessc --no-js

Lint
It checks the syntax and reports error without any output.
lessc --lint
lessc -l

Silent
It forcibly stops the display of error messages.
lessc --silent
lessc -s

Strict Imports
It force evaluates imports.
lessc --strict-imports

Allow Imports from Insecure HTTPS Hosts
It imports from the insecure HTTPS hosts.
lessc --insecure

Version
It displays the version number and exits.
lessc -version
lessc -v

Compress
It helps in removing the whitespaces and compress the output.
lessc -x
lessc --compress

Source Map Output Filename
It generates the sourcemap in less. If sourcemap option is defined without filename then it will use the extension map with the Less file name as source.
lessc --source-map
lessc -source-map = file.map

Source Map Rootpath
Rootpath is specified and should be added to Less file paths inside the sourcemap and also to the map file which is specified in your output css.
lessc --source-map-rootpath = dev-files/

Source Map Basepath
A path is specified which has to be removed from the output paths. Basepath is opposite of the rootpath option.
lessc --source-map-basepath = less-files/

Source Map Less Inline
All the Less files should be included in the sourcemap.
lessc --source-map-less-inline

Source Map Map Inline
It specifies that in the output css the map file should be inline.
lessc --source-map-map-inline

Source Map URL
A URL is allowed to override the points in the map file in the css.
lessc --source-map-url = ../my-map.json

Rootpath
It sets paths for URL rewriting in relative imports and urls.
lessc -rp=resources/
lessc --rootpath=resources/

Relative URLs
In imported files, the URL are re-written so that the URL is always relative to the base file.
lessc -ru
lessc --relative-urls

Strict Math
It processes all Math function in your css. By default, it's off.
lessc -sm = on
lessc --strict-math = on

Strict Units
It allows mixed units.
lessc -su = on
lessc --strict-units = on

Global Variable
A variable is defined which can be referenced by the file.
lessc --global-var = "background = green"


Modify Variable
This is unlike global variable option; it moves the declaration at the end of your less file.
lessc --modify-var = "background = green"

URL Arguments
To move on to every URL, an argument is allowed to specify.
lessc --url-args = "arg736357"

Line Numbers
Inline source-mapping is generated.
lessc --line-numbers = comments
lessc --line-numbers = mediaquery
lessc --line-numbers = all

Plugin
It loads the plugin.
lessc --clean-css
lessc --plugin = clean-css = "advanced"


    20 Lectures 
     1 hours 

 Anadi Sharma

    44 Lectures 
     7.5 hours 

 Eduonix Learning Solutions

    17 Lectures 
     2 hours 

 Zach Miller

    23 Lectures 
     1.5 hours 

 Zach Miller

    34 Lectures 
     4 hours 

 Syed Raza

    31 Lectures 
     3 hours 

 Harshit Srivastava
 Print
 Add Notes
 Bookmark this page