You should keep in mind that with gulp you can just chain operations to the glob pattern.
Not quite sure why you need gulp.watch when you can use the built-in observer, this plugin is useful in difficult situations, and itβs not, but you can stick with it if you really want to,
Remember to return your thread so that gulp knows when the task is complete.
I also usually wrap all my watchers in one watch task , no need to separate them.
For me, your gulpfile should look like this:
var gulp = require('gulp'), less = require('gulp-less'), cssmin = require('gulp-cssmin'), rename = require('gulp-rename'); gulp.task('watch', function () { gulp.watch('./*.less', ['less']); }); gulp.task('less', function () { return gulp.src('./*.less') .pipe(less().on('error', function (err) { console.log(err); })) .pipe(cssmin().on('error', function(err) { console.log(err); })) .pipe(rename({suffix: '.min'})) .pipe(gulp.dest('./')); }); gulp.task('default', ['less', 'watch']);
AperΓ§u
source share