Friday, March 3, 2017

Less - Command Line Usage

Using the command line we can compile the .less file to .css.

Installing lessc for Use Globally

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 eg: npm install less@1.6.2 -g

Installing for Node Development

The following command is used to install lessc latest version in your project folder.
npm i less -save-dev
It is also added to the devDependencies in your project package.json.
  • Beta releases of lessc
    It is tagged as beta when lessc structure is published to npm where new functionality is developed periodically. less -v is used to get the current version.
  • Installing an unpublished development version of lessc
    The commit - ish is to be specify, when we wish to install an unpublished version of lessc and follow instruction for identifying a git URL as a dependency. This will make sure that you are using the correct of leesc for your project.

Server-Side and Command Line Usage

bin/lessc includes binary in the repository. It works windows, OS X and nodejs on *nix.

Command Line Usage

Input is read from stdin when source is set to dash or hypen(-).
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

Options

Following are the options used in command line usage.
S.N. Options & Description Command
1 Help
Help message is displayed with the options available.
lessc -help
lessc -h
2 Include Paths
It includes the available paths to the library which you wish to referenced simply and relatively in the less files. The paths in windows are separated by colon(:) or semicolon(;).
lessc --include-path=PATH1;PATH2
3 Makefile
It output a makefile import dependencies list to stdout.
lessc -M
lessc --depends
4 No Color
Colorized output is disabled.
lessc --no-color
5 No IE Compatibility
IE compatibility checks are disabled.
lessc --no-ie-compat
6 Disable Javascript
Disables the javascript in less files.
lessc --no-js
7 Lint
Checks the syntax and reports error without any output.
lessc --lint
lessc -l
8 Silent
Forcibly stops the display of error messages.
lessc --silent
lessc -s
9 Strict Imports
Force evaluation of imports.
lessc --strict-imports
10 Allow Imports from Insecure HTTPS Hosts
Imports are allowed from the insecure HTTPS hosts.
lessc --insecure
11 Version
Displays the version number and exits.
lessc -version
lessc -v
12 Compress
Helps in removing the whitespaces and compress the output.
lessc -x
lessc --compress
13 Source Map Output Filename
It generates sourcemap in less. If sourcemap option is defined without filename then it will use extension map with the source less file name.
lessc --source-map
lessc -source-map=file.map
14 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/
15 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/
16 Source Map Less Inline
All the less files should be included in the sourcemap.
lessc --source-map-less-inline
17 Source Map Map Inline
It specifies that in the output css the map file should be inline.
lessc --source-map-map-inline
18 Source Map URL
The URL are allowed to override that points at the map file in the css.
lessc --source-map-url=../my-map.json
19 Rootpath
It sets paths for URL rewriting in relative imports and urls.
lessc -rp=resources/
lessc --rootpath=resources/
20 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
21 Strict Math
It processes all math function in your css. By default it's off
lessc -sm=on
lessc --strict-math=on
22 Strict Units
It allows the mixed units.
lessc -su=on
lessc --strict-units=on
23 Global Variable
A variable is defined which can be referenced by the file.
lessc --global-var= "background=green"
24 Modify Variable
Modify variable is opposite of global variable option, it moves the declaration at the end of your less file.
lessc --modify-var= "background=green"
25 URL Arguments
To move on to every URL, an argument is allowed to specify.
lessc --url-args= "arg736357"
26 Line Numbers
Inline source-mapping is generated.
lessc --line-numbers=comments
lessc --line-numbers=mediaquery
lessc --line-numbers=all
27 Plugin
It loads the plugin.
lessc --clean-css
lessc --plugin=clean-css="advanced"

No comments:

Post a Comment