1 | # PostCSS LESS Syntax - Work in Progress
|
2 |
|
3 | [PostCSS]: https://github.com/postcss/postcss
|
4 | [PostCSS-SCSS]: https://github.com/postcss/postcss-scss
|
5 | [LESS]: http://lesless.org
|
6 | [Autoprefixer]: https://github.com/postcss/autoprefixer
|
7 | [Stylelint]: http://stylelint.io/
|
8 |
|
9 | > This project is not stable and is in development. If you'd like to contribute, please submit a Pull Request.
|
10 |
|
11 | <img align="right" width="95" height="95"
|
12 | title="Philosopher's stone, logo of PostCSS"
|
13 | src="http://postcss.github.io/postcss/logo.svg">
|
14 |
|
15 | [![Build Status](https://img.shields.io/travis/webschik/postcss-less.svg?branch=develop)](https://travis-ci.org/webschik/postcss-less)
|
16 | [![npm Downloads](https://img.shields.io/npm/dt/postcss-less.svg)](https://www.npmjs.com/package/postcss-less)
|
17 | [![npm Version](https://img.shields.io/npm/v/postcss-less.svg)](https://www.npmjs.com/package/postcss-less)
|
18 | [![npm License](https://img.shields.io/npm/l/postcss-less.svg)](https://www.npmjs.com/package/postcss-less)
|
19 | [![js-strict-standard-style](https://img.shields.io/badge/code%20style-strict-117D6B.svg)](https://github.com/keithamus/eslint-config-strict)
|
20 |
|
21 | A [LESS] parser for [PostCSS].
|
22 |
|
23 | **This module does not compile LESS.** It simply parses mixins and variables so that PostCSS plugins can then transform LESS source code alongside CSS.
|
24 |
|
25 | ## Use Cases
|
26 |
|
27 | * lint your LESS code with 3rd-part plugins.
|
28 | * apply PostCSS transformations (such as [Autoprefixer](https://github.com/postcss/autoprefixer)) directly to the LESS source code
|
29 |
|
30 | ## Usage
|
31 |
|
32 | ### LESS Transformations
|
33 |
|
34 | The main use case of this plugin is to apply PostCSS transformations directly
|
35 | to LESS source code. For example, if you ship a theme written in LESS and need
|
36 | [Autoprefixer] to add the appropriate vendor prefixes to it.
|
37 |
|
38 | ```js
|
39 | const syntax = require('postcss-less');
|
40 | postcss(plugins).process(lessText, { syntax: syntax }).then(function (result) {
|
41 | result.content // LESS with transformations
|
42 | });
|
43 | ```
|
44 |
|
45 | ### Comment Node
|
46 |
|
47 | #### Inline comments
|
48 |
|
49 | This module also enables parsing of single-line comments in CSS source code.
|
50 |
|
51 | ````less
|
52 | :root {
|
53 | // Main theme color
|
54 | --color: red;
|
55 | }
|
56 | ````
|
57 |
|
58 | Note that you don't need a special stringifier to handle the output; the default
|
59 | one will automatically convert single line comments into block comments.
|
60 | If you need to get inline comments, use stringifier from `postcss-less` module:
|
61 |
|
62 | ````js
|
63 | import postCssLess from 'postcss-less';
|
64 |
|
65 | const root = postCssLess.parse('// Hello world');
|
66 |
|
67 | root.first.toString(); // returns '/* Hello world */'
|
68 |
|
69 | root.first.toString({
|
70 | stringify: postCssLess.stringify
|
71 | }); // returns '// Hello world'
|
72 | ````
|
73 |
|
74 | #### Comment Node
|
75 |
|
76 | `postcss-less` extends the [default structure](https://github.com/postcss/postcss/blob/master/docs/api.md#comment-node) of Comment node
|
77 |
|
78 | ##### comment.inline
|
79 | It's inline comment or not.
|
80 | ````js
|
81 | import postCssLess from 'postcss-less';
|
82 |
|
83 | const root = postCssLess.parse('// Hello world');
|
84 |
|
85 | root.first.inline // => true
|
86 | ````
|
87 |
|
88 | ##### comment.block
|
89 | It's block comment or not.
|
90 | ````js
|
91 | import postCssLess from 'postcss-less';
|
92 |
|
93 | const root = postCssLess.parse('/* Hello world */');
|
94 |
|
95 | root.first.block // => true
|
96 | ````
|
97 |
|
98 | ##### comment.raws.begin
|
99 | Precending characters of comment node: `//` or `/*`.
|
100 |
|
101 | ##### comment.raws.content
|
102 | Raw content of the comment.
|
103 | ````js
|
104 | import postCssLess from 'postcss-less';
|
105 |
|
106 | const root = postCssLess.parse('// Hello world');
|
107 |
|
108 | root.first.raws.content // => '// Hello world'
|
109 | ````
|
110 |
|
111 | ### Stylelint support
|
112 | `postcss-less` parser **is not compatible** with `Stylelint`, because `Stylelint` can't process syntax tree from `postcss-less`!
|
113 |
|
114 | ## Contribution
|
115 | Please, check our guidelines: [CONTRIBUTING.md](./CONTRIBUTING.md)
|
116 |
|
117 | ## Attribution
|
118 |
|
119 | This module is based on the work of [postcss-scss](https://github.com/postcss/postcss-scss) library and includes the `LESS` parser efforts of [github:gilt/postcss-less](https://github.com/gilt/postcss-less)
|
120 |
|
\ | No newline at end of file |