Skip to content

Commit ad25db6

Browse files
committed
Merge pull request #245 from less/v2_0_0
V2 pull request
2 parents e81d3b5 + 8001974 commit ad25db6

8 files changed

+298
-92
lines changed

content/home/using-less.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ $ lessc styles.less > styles.css
2929

3030
To output minified CSS, simply pass the `-x` option. If you would like more involved minification,
3131
the [Clean CSS](https://github.com/GoalSmashers/clean-css) is also available with
32-
the `--clean-css` option.
32+
the `--clean-css` [plugin](https://github.com/less/less-plugin-clean-css).
3333

34-
To see all the command line options run lessc without parameters.
34+
To see all the command line options run lessc without parameters or see [Usage]({{resolve 'usage'}}).
3535

3636
## Usage in Code
3737

@@ -53,37 +53,26 @@ which will output
5353
}
5454
```
5555

56-
you may also manually invoke the parser and compiler:
57-
58-
```js
59-
var parser = new(less.Parser);
60-
61-
parser.parse('.class { width: (1 + 1) }', function (err, tree) {
62-
if (err) {
63-
return console.error(err)
64-
}
65-
console.log(tree.toCSS());
66-
});
67-
```
68-
6956
## Configuration
7057

7158
You may pass some options to the compiler:
7259

7360
```js
74-
var parser = new(less.Parser)({
75-
paths: ['.', './lib'], // Specify search paths for @import directives
76-
filename: 'style.less' // Specify a filename, for better error messages
77-
});
61+
var less = require('less');
7862

79-
parser.parse('.class { width: (1 + 1) }', function (e, tree) {
80-
tree.toCSS({
81-
// Minify CSS output
82-
compress: true
83-
});
84-
});
63+
less.render('.class { width: (1 + 1) }',
64+
{
65+
paths: ['.', './lib'], // Specify search paths for @import directives
66+
filename: 'style.less', // Specify a filename, for better error messages
67+
compress: true // Minify CSS output
68+
},
69+
function (e, css) {
70+
console.log(css);
71+
});
8572
```
8673

74+
See [Usage]({{resolve 'usage'}}) for more information.
75+
8776
## Third party tools
8877

8978
See the [Usage]({{resolve 'usage'}}) section for details of other tools.

content/usage/command-line-usage.md

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Note that a [tilde version range][] will be automatically specified in `package.
3030

3131
#### Beta releases of lessc
3232

33-
Periodically, as new functionality is being developed, lessc builds will be published to npm, tagged as. These builds will _not_ be published as a `@latest` official release, and will typically have a build number or alpha/beta/release candidate designation.
33+
Periodically, as new functionality is being developed, lessc builds will be published to npm, tagged as beta. These builds will _not_ be published as a `@latest` official release, and will typically have beta in the version (use `lessc -v` to get current version).
3434

35-
Since patch releases are non-breaking we will publish patch releases immediately and alpha/beta/candidate versions will be published as minor or major version upgrades (we endevour since 1.4.0 to follow [semantic versioning](http://semver.org/)).
35+
Since patch releases are non-breaking we will publish patch releases immediately and alpha/beta/candidate versions will be published as minor or major version upgrades (we endeavour since 1.4.0 to follow [semantic versioning](http://semver.org/)).
3636

3737
#### Installing an unpublished development version of lessc
3838

@@ -68,7 +68,9 @@ $ lessc bootstrap.less bootstrap.css
6868
$ lessc -x bootstrap.less bootstrap.css
6969
```
7070

71-
### Help
71+
### Options
72+
73+
#### Help
7274

7375
```bash
7476
lessc --help
@@ -77,7 +79,7 @@ lessc --h
7779

7880
Prints a help message with available options and exits.
7981

80-
### Include paths
82+
#### Include paths
8183

8284
```bash
8385
lessc --include-path=PATH1;PATH2
@@ -92,34 +94,34 @@ In node, set a paths option
9294
{ paths: ['PATH1', 'PATH2'] }
9395
```
9496

95-
### Makefile
97+
#### Makefile
9698

9799
```bash
98100
lessc -M
99101
lessc --depends
100102
```
101103

102-
### No Color
104+
#### No Color
103105

104106
```bash
105107
lessc --no-color
106108
```
107109

108-
### No IE Compatability
110+
#### No IE Compatability
109111

110112
```bash
111113
lessc --no-ie-compat
112114
```
113115

114116
Currently only used for the data-uri function to ensure that images aren't created that are too large for the browser to handle.
115117

116-
### Disable JavaScript
118+
#### Disable JavaScript
117119

118120
```bash
119121
lessc --no-js
120122
```
121123

122-
### Lint
124+
#### Lint
123125

124126
```bash
125127
lessc --lint
@@ -128,33 +130,35 @@ lessc --l
128130

129131
Runs the less parser and just reports errors without any output.
130132

131-
### Silent
133+
#### Silent
132134

133135
```bash
134136
lessc -s
135137
lessc --silent
136138
```
137139

138-
### Strict Imports
140+
Stops any warnings from being shown.
141+
142+
#### Strict Imports
139143

140144
```bash
141145
lessc --strict-imports
142146
```
143147

144-
### Allow imports from insecure https hosts
148+
#### Allow imports from insecure https hosts
145149

146150
```bash
147151
lessc --insecure
148152
```
149153

150-
### Version
154+
#### Version
151155

152156
```bash
153157
lessc -v
154158
lessc --version
155159
```
156160

157-
### Compress
161+
#### Compress
158162

159163
```bash
160164
lessc -x
@@ -163,25 +167,11 @@ lessc --compress
163167

164168
Compress using less built-in compression. This does an okay job but does not utilise all the tricks of dedicated css compression. Please feel free to improve our compressed output with a pull request.
165169

166-
### Clean CSS
167-
168-
```bash
169-
lessc --clean-css
170-
```
171-
172-
Clean CSS is our minifer of choice if you want to get the most minified you can. This option switches it on.
173-
174-
Note - it does not yet support sourcemaps, for that you can only use our own compression.
175-
176-
### Clean CSS Options
177-
178-
```bash
179-
lessc --clean-css --clean-option=--selectors-merge-mode:ie8 --clean-option=--advanced
180-
```
170+
#### Clean CSS
181171

182-
Use this to pass options to clean css. The default options are the safest, so are IE8 compatible.
172+
In v2 of less, Clean CSS is no longer included as a direct dependency. To use clean css with lessc, use the [clean css plugin](https://github.com/less/less-plugin-clean-css).
183173

184-
### Source Map Output Filename
174+
#### Source Map Output Filename
185175

186176
```bash
187177
lessc --source-map
@@ -190,14 +180,16 @@ lessc --source-map=file.map
190180

191181
Tells less to generate a sourcemap. If you have the sourcemap option without a filename it will use the source less file name but with the extension map.
192182

193-
### Source Map Rootpath
183+
#### Source Map Rootpath
194184

195185
```bash
196186
lessc --source-map-rootpath=dev-files/
197187
```
198188

199189
Specifies a rootpath that should be prepended to each of the less file paths inside the sourcemap and also to the path to the map file specified in your output css.
200190

191+
Because the basepath defaults to the directory of the input less file, the rootpath defaults to the path from the sourcemap output file to the base directory of the input less file.
192+
201193
Use this option if for instance you have a css file generated in the root on your web server but have your source less/css/map files in a different folder. So for the option above you might have
202194

203195
```bash
@@ -206,15 +198,17 @@ dev-files/output.map
206198
dev-files/main.less
207199
```
208200

209-
### Source Map Basepath
201+
#### Source Map Basepath
210202

211203
```bash
212204
lessc --source-map-basepath=less-files/
213205
```
214206

215-
This is the opposite of the rootpath option, it specifies a path which should be removed from the output paths. For instance if you are compiling a file in the less-files directory but the source files will be available on your web server in the root or current directory, you can specify this to remove the additional `less-files` part of the path
207+
This is the opposite of the rootpath option, it specifies a path which should be removed from the output paths. For instance if you are compiling a file in the less-files directory but the source files will be available on your web server in the root or current directory, you can specify this to remove the additional `less-files` part of the path.
216208

217-
### Source Map Less Inline
209+
It defaults to the path to the input less file.
210+
211+
#### Source Map Less Inline
218212

219213
```bash
220214
lessc --source-map-less-inline
@@ -224,23 +218,23 @@ This option specifies that we should include all of the Less files in to the sou
224218

225219
This can be used in conjunction with the map inline option so that you do not need to have any additional external files at all.
226220

227-
### Source Map Map Inline
221+
#### Source Map Map Inline
228222

229223
```bash
230224
lessc --source-map-map-inline
231225
```
232226

233227
This option specifies that the map file should be inline in the output CSS. This is not recommended for production, but for development it allows the compiler to produce a single output file which in browsers that support it, use the compiled css but show you the non-compiled less source.
234228

235-
### Source Map URL
229+
#### Source Map URL
236230

237231
```bash
238232
lessc --source-map-url=../my-map.json
239233
```
240234

241235
Allows you to override the URL in the css that points at the map file. This is for cases when the rootpath and basepath options are not producing exactly what you need.
242236

243-
### Rootpath
237+
#### Rootpath
244238

245239
```bash
246240
lessc -rp=resources/
@@ -251,7 +245,7 @@ Allows you to add a path to every generated import and url in your css. This doe
251245

252246
For instance, if all the images the css use are in a folder called resources, you can use this option to add this on to the URL's and then have the name of that folder configurable.
253247

254-
### Relative URLs
248+
#### Relative URLs
255249

256250
```bash
257251
lessc -ru
@@ -287,14 +281,14 @@ but with this option on it will instead output
287281

288282
You may also want to consider using the data-uri function instead of this option, which will embed images into the css.
289283

290-
### Strict Math
284+
#### Strict Math
291285

292286
```bash
293287
lessc -sm=on
294288
lessc --strict-math=on
295289
```
296290

297-
Defaults to Off.
291+
Defaults to Off.
298292

299293
Without this option on Less will try and process all maths in your css e.g.
300294

@@ -326,7 +320,7 @@ With strict math on, only maths that is inside un-necessary parenthesis will be
326320

327321
We originally planned to default this to true in the future, but it has been a contraversial option and we are considering whether we have solved the problem in the right way, or whether less should just have exceptions for instances where `/` is valid or calc is used.
328322

329-
### Strict Units
323+
#### Strict Units
330324

331325
```bash
332326
lessc -su=on
@@ -347,31 +341,31 @@ In this case, things are clearly not right - a length multiplied by a length giv
347341

348342
With strict units on, we assume this is a bug in the calculation and throw an error.
349343

350-
### Global Variable
344+
#### Global Variable
351345

352346
```bash
353347
lessc --global-var="my-background=red"
354348
```
355349

356350
This option defines a variable that can be referenced by the file. Effectively the declaration is put at the top of your base Less file, meaning it can be used but it also can be overridden if this variable is defined in the file.
357351

358-
### Modify Variable
352+
#### Modify Variable
359353

360354
```bash
361355
lessc --modify-var="my-background=red"
362356
```
363357

364358
As opposed to the global variable option, this puts the declaration at the end of your base file, meaning it will override anything defined in your Less file.
365359

366-
### URL Arguments
360+
#### URL Arguments
367361

368362
```bash
369363
lessc --url-args="cache726357"
370364
```
371365

372366
This option allows you to specify a argument to go on to every URL. This may be used for cache-busting for instance.
373367

374-
### Line Numbers
368+
#### Line Numbers
375369

376370
```bash
377371
lessc --line-numbers=comments
@@ -380,3 +374,17 @@ lessc --line-numbers=all
380374
```
381375

382376
Generates inline source-mapping. This was the only option before browsers started supporting sourcemaps. We are consider deprecating, so please get in touch if you want this option to stick around.
377+
378+
#### Plugin
379+
380+
```bash
381+
lessc --clean-css
382+
lessc --plugin=clean-css="advanced"
383+
```
384+
385+
--plugin Loads a plugin. You can also omit the --plugin= if the plugin begins
386+
less-plugin. E.g. the clean css plugin is called less-plugin-clean-css
387+
once installed (npm install less-plugin-clean-css), use either with
388+
--plugin=less-plugin-clean-css or just --clean-css
389+
specify options afterwards e.g. --plugin=less-plugin-clean-css="advanced"
390+
or --clean-css="advanced"

content/usage/developing-less.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,27 @@ Other grunt commands
3131
* `grunt stable` to create a new release
3232
* `grunt readme` to generate a new readme.md in the root directory (after each release)
3333

34+
## How to run less in other environments
35+
36+
If you look in the libs folder you will see `less`, `less-node`, `less-browser`. The less folder is pure javascript with no environment
37+
specifics. if you require `less/libs/less`, you get a function that takes an environment object and an array of file managers. The file
38+
managers are the same file managers that can also be written as a plugin.
39+
40+
```js
41+
var createLess = require("less/libs/less"),
42+
myLess = createLess(environment, [myFileManager]);
43+
```
44+
45+
The environment api is specified in [less/libs/less/environment/environment-api.js](https://github.com/less/less.js/blob/master/lib/less/environment/environment-api.js)
46+
and the file manager api is specified in [less/libs/less/environment/file-manager-api.js](https://github.com/less/less.js/blob/master/lib/less/environment/file-manager-api.js).
47+
48+
For file managers we highly recommend setting the prototype as a new AbstractFileManager - this allows you to override what is needed and allows us
49+
to implement new functions without breaking existing file managers. For an example of file managers, see the 2 node implementations, the browser implementation or
50+
the npm import plugin implementation.
51+
3452
## Guide
3553

36-
If you look at [http://www.gliffy.com/go/publish/4784259](http://www.gliffy.com/go/publish/4784259), This is an overview diagram of how less works.
54+
If you look at [http://www.gliffy.com/go/publish/4784259](http://www.gliffy.com/go/publish/4784259), This is an overview diagram of how less works. Warning! It needs updating with v2 changes.
3755

3856
## Books
3957

0 commit comments

Comments
 (0)