0

Here's my gulpfile.js contents:

const fs    = require( 'fs' );
const gulp  = require( 'gulp' );


exports.watch = gulp.series( watch );


function watch() {

    const file = 'src/style.scss';

    console.log( fs.readFileSync( file ).length );

    gulp.watch( file, gulp.series( sass ) );
}


function sass( done ) {
    console.log( 'Success!' );
    done();
}

When I run gulp watch, it starts watching but changes made to src/style.scss don't reflect. I can see length of the file content on console, but can never see the Success! message.

Before posting it here, I've gone through the Gulp4 documentation over and over again, checked a lot of solutions regarding Gulp Watch including this one, but won't be able to figure out the exact issue.

Your help on this is highly appreciated. Thanks in advance.


Update

The following code is working as expected on Gulp 3.9.1

const gulp = require( 'gulp' );


gulp.task( 'default', () => {
    gulp.watch( 'src/style.scss', [ 'sass' ] );
});


gulp.task( 'sass', () => {
    console.log( 'Success!' );
});

But the following one is not working on Gulp 4.0.0

const gulp = require( 'gulp' );


exports.default = gulp.series( watch );


function watch( done ) {
    gulp.watch( 'src/style.scss', gulp.series( sass ) );
    done();
}


function sass( done ) {
    console.log( 'Success!' );
    done();
}

Environment:

  • OS: CentOS Linux release 7.6.1810 (Core)
  • NPM: 6.4.1
  • Node: v10.15.1

Am I doing any silly mistake, or it is a BUG?

A.N.M. Saiful Islam
  • 2,118
  • 5
  • 28
  • 34
  • I get the Success message every time when i change something in `src/style.scss`. (tested with your gulpfile.js and gulp 4.0.0) – d-h-e Feb 27 '19 at 12:35
  • @d-h-e thank you for your reply. Yes, this is supposed to work, but unfortunately it is not. To make sure there no issue with file streaming, I've written a code for Gulp 3.9.1 and translated the same code for Gulp 4.0.0. Strangely, the code works on Gulp 3.9.1, but not on Gulp 4.0.0. Please refer to the question updates for details. – A.N.M. Saiful Islam Feb 27 '19 at 12:54
  • I also cannot reproduce your problem. Pasted your code into a test directory and it worked fine. I might suggest putting your sass declaration first, then watch, then the export statement - v4 seems to be pickier on the order of declarations. But it works as is for me so... – Mark Feb 27 '19 at 16:26

0 Answers0