📜  LESS-命令行用法

📅  最后修改于: 2020-10-22 07:16:20             🧑  作者: Mango


 

使用命令行,我们可以将.less文件编译为.css

安装供全球使用的lessc

以下命令用于通过npm(node package manager)安装lessc,以使lessc全局可用。

npm install less -g

您还可以在软件包名称后添加特定版本。例如npm install less@1.6.2 -g

安装进行节点开发

以下命令用于在项目文件夹中安装最新版本的lessc

npm i less -save-dev

它还会添加到项目package.json中的devDependencies中。

Lessc的Beta版本

lessc结构发布到npm时,它被标记为beta。这里,新功能定期开发。 less -v用于获取当前版本。

安装未发布的lessc开发版本

当我们继续安装未发布的lessc版本时,将指定提交,并且需要遵循说明将git URL标识为依赖项。这将确保您为项目使用正确版本的leesc。

服务器端和命令行用法

bin / lessc在存储库中包含二进制文件。它可以与Windows,OS X和* nix上的nodejs一起使用。

命令行用法

当source设置为破折号或连字符(-)时,将从stdin读取输入

lessc [option option = parameter ...]  [destination]

例如,我们可以使用以下命令将.less编译为.css-

lessc stylesheet.less stylesheet.css

我们可以使用以下命令将.less编译为.css并缩小结果。

lessc -x stylesheet.less stylesheet.css

选件

下表列出了命令行用法中使用的选项-

Sr.No. 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. 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
3 Makefile

It generates a makefile import dependencies list to stdout as output.

lessc -M
lessc --depends
4 No Color

It disables colorized output.

lessc --no-color
5 No IE Compatibility

It disables IE compatibility checks.

lessc --no-ie-compat
6 Disable Javascript

It disables the javascript in less files.

lessc --no-js
7 Lint

It checks the syntax and reports error without any output.

lessc --lint
lessc -l
8 Silent

It forcibly stops the display of error messages.

lessc --silent
lessc -s
9 Strict Imports

It force evaluates imports.

lessc --strict-imports
10 Allow Imports from Insecure HTTPS Hosts

It imports from the insecure HTTPS hosts.

lessc --insecure
11 Version

It displays the version number and exits.

lessc -version
lessc -v
12 Compress

It helps in removing the whitespaces and compress the output.

lessc -x
lessc --compress
13 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
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

A URL is allowed to override the points in 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 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

This is unlike 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"