gulp-watch-less2

Gulp plugin for watching .less files and their @imports

Usage no npm install needed!

<script type="module">
  import gulpWatchLess2 from 'https://cdn.skypack.dev/gulp-watch-less2';
</script>

README

gulp-watch-less2 NPM version Build Status Dependency Status

Gulp plugin for watching .less files and their @imports, based on chokidar

Install

$ npm i -D gulp-watch-less2

Protip: until gulpjs 4.0 is released, you can use gulp-plumber to avoid watch process be terminated by errors.

Usage

var gulp = require('gulp');
var watchLess = require('gulp-watch-less2');
var less = require('gulp-less');
var lessGlobs = 'less/main-*.less';
gulp.task('default', function () {
  return gulp.src(lessGlobs)
    .pipe(watchLess(lessGlobs, {verbose: true}))
    .pipe(less())
    .pipe(gulp.dest('dist'));
});

Important Note

  • Strongly recommand using specific glob to filter import files. E.g. main-*.less to ignore import files which filename is not start with main-.

The following actions will trigger recompile main-*.less.

  • Add/Reorder/Remove @import statement(s) in main-*.less
  • Change code of file imported in main-*.less
  • Change code of main-*.less

API

GulpWatchLess(glob, [options, callback])

Returns pass-through stream, that will emit vinyl files (with additional event property) that corresponds to event on file-system.

glob

Glob can be a node-glob string or array of strings.

Options

See documentation on chokidar task

options.less

Type: object
Default: {}

Optional options passed through to the less.Parser instance.

Callback function(events, done)

See documentation on chokidar task

License

MIT © John Xiao