Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

121
Views
Gulp 4 watch task only runs once

My gulpfile works well but when calling the watch task and then making a change to a watched file it only seems to run once and then no longer watches the file.

I have tried using callbacks but it doesn't seem to resolve my situation. I have recently changed from Gulp 3 to 4 and I am possibly missing a core piece of functionality.

// Load plugins
const gulp = require("gulp");
const sass = require('gulp-sass')(require('sass'))

// CSS task
function css() {
    process.chdir('./ui/src/sass/'); // Change current working directory
    return gulp.src('**/*.scss')
      .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
      .pipe(gulp.dest('../../dist/css/'));
}

// Watch files
function watchFiles() {
  gulp.watch( 'ui/src/sass/**/*.scss' ).on( 'change', gulp.series(css));
}

const watch = gulp.parallel(watchFiles);

// export tasks
exports.css = css;
exports.watch = watch;
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs