UNPKG

4.42 kBMarkdownView Raw
1# gulp-less
2
3
4> A [LESS](http://lesscss.org/) plugin for Gulp
5
6[![NPM Version](https://img.shields.io/npm/v/gulp-less.svg)](https://www.npmjs.com/package/gulp-less)
7[![Build Status](https://img.shields.io/travis/gulp-community/gulp-less.svg)](https://travis-ci.org/gulp-community/gulp-less)
8
9## Information
10
11<table>
12<tr>
13<td>Package</td><td>gulp-less</td>
14</tr>
15<tr>
16<td>Description</td>
17<td>Less plugin for gulp</td>
18</tr>
19<tr>
20<td>Node Version</td>
21<td>>= 0.10</td>
22</tr>
23<tr>
24<td>Less Version</td>
25<td>2.x | 3.7+</td>
26</tr>
27<tr>
28<td>Gulp Version</td>
29<td>3.x</td>
30</tr>
31</table>
32
33## Installation
34
35```
36npm install gulp-less
37```
38
39## Basic Usage
40
41```js
42var less = require('gulp-less');
43var path = require('path');
44
45gulp.task('less', function () {
46 return gulp.src('./less/**/*.less')
47 .pipe(less({
48 paths: [ path.join(__dirname, 'less', 'includes') ]
49 }))
50 .pipe(gulp.dest('./public/css'));
51});
52```
53
54## Options
55
56The options you can use [can be found here](http://lesscss.org/#using-less-configuration). Below is a list of valid options as of the time of writing:
57
58- `paths`: Array of paths to be used for `@import` directives
59- `plugins`: Array of less plugins ([details](#using-plugins))
60
61The `filename` option is not necessary, it's handled automatically by this plugin. The `compress` option is not supported -- if you are trying to minify your css, use a css minifier. No `sourceMap` options are supported -- if you are trying to generate sourcemaps, use [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps).
62
63## Using Plugins
64
65Less now supports plugins, which can add additional functionality. Here's an example of how to use a plugin with `gulp-less`.
66
67```js
68var LessAutoprefix = require('less-plugin-autoprefix');
69var autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] });
70
71return gulp.src('./less/**/*.less')
72 .pipe(less({
73 plugins: [autoprefix]
74 }))
75 .pipe(gulp.dest('./public/css'));
76```
77
78More info on LESS plugins can be found at http://lesscss.org/usage/#plugins, including a current list of all available plugins.
79
80## Source Maps
81
82`gulp-less` can be used in tandem with [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) to generate source maps for your files. You will need to initialize [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) prior to running the gulp-less compiler and write the source maps after, as such:
83
84```js
85var sourcemaps = require('gulp-sourcemaps');
86
87gulp.src('./less/**/*.less')
88 .pipe(sourcemaps.init())
89 .pipe(less())
90 .pipe(sourcemaps.write())
91 .pipe(gulp.dest('./public/css'));
92```
93
94By default, [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) writes the source maps inline in the compiled CSS files. To write them to a separate file, specify a relative file path in the `sourcemaps.write()` function, as such:
95
96```js
97var sourcemaps = require('gulp-sourcemaps');
98
99gulp.src('./less/**/*.less')
100 .pipe(sourcemaps.init())
101 .pipe(less())
102 .pipe(sourcemaps.write('./maps'))
103 .pipe(gulp.dest('./public/css'));
104```
105
106## Error Handling
107
108By default, a gulp task will fail and all streams will halt when an error happens. To change this behavior check out the error handling documentation [here](https://github.com/gulpjs/gulp/blob/master/docs/recipes/combining-streams-to-handle-errors.md)
109
110## License
111
112(MIT License)
113
114Copyright (c) 2015 Plus 3 Network dev@plus3network.com
115
116Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
117
118The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
119
120THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.