Gulp works with tasks but not with watchers

Viewed 15

I have this code:

var gulp = require('gulp'),
rename = require('gulp-rename'),
less = require('gulp-less'),
path = require('path'),
cleanCSS = require('gulp-clean-css'),
uglify = require('gulp-uglify');

const { watch, series, task } = require('gulp');

task('uglify', async function () {
  gulp.src('assets/js/*.js')
  .pipe(uglify())
  .pipe(rename({ suffix: '.min' }))
  .pipe(gulp.dest('assets/public/js/'))
});

task('less', function () {
  return gulp.src('assets/less/*.less')
    .pipe(less({
      paths: [ path.join(__dirname, 'less', 'fragments') ]
    }))
    .pipe(cleanCSS({compatibility: 'ie8'}))
    .pipe(rename({ suffix: '.min' }))
    .pipe(gulp.dest('assets/public/css/'));
});

task('default', series('uglify', 'less'));

/* task('default', function (){
  watch('assets/less/*.less', series(less));
  watch('assets/js/*.js', series(uglify));
  return;
}); */

When I run the initial code, the first default, gulp works correctly and compresses my files successfully. However, when I change it to the one that has the watchers, it doesn't react to the changes, only this appears in the console: 16:02:09] Starting 'default'... 16:02:59] Starting ''...

Whay can I do?

0 Answers
Related