2

As I mentioned in the title there is a problem running gulp.watch. It runs watch only after first change in the file, when I changing second, third and etc it doesn't run task.
Below is my gulpfile.js:

var gulp = require('gulp');
var babel = require('gulp-babel');
var rename = require("gulp-rename");
var del = require('del');
var less = require('gulp-less');

gulp.task('es6', function () {
   return gulp.src('./test.js')
       .pipe(rename(function (path) {
           path.basename += "-es6";
           return path;
       }))
       .pipe(babel())
       .pipe(gulp.dest('./'))
});

gulp.task('clean', function () {
    return del('./test-es6.js');
});

gulp.task('watch', function () {
   gulp.watch( './test.js', gulp.series('es6') );
    console.log('Running watch...');
});

gulp.task('default', gulp.series('clean', 'es6', gulp.parallel('watch') ));

And some logs :

$: gulp
[14:22:40] Using gulpfile /var/www/html/es2015/gulpfile.js
[14:22:40] Starting 'default'...
[14:22:40] Starting 'clean'...
[14:22:40] Finished 'clean' after 11 ms
[14:22:40] Starting 'es6'...
[14:22:43] Finished 'es6' after 2.11 s
[14:22:43] Starting '<parallel>'...
[14:22:43] Starting 'watch'...
Running watch...
[14:22:55] Starting '<series>'...
[14:22:55] Starting 'es6'...
[14:22:55] Finished 'es6' after 42 ms
[14:22:55] Finished '<series>' after 43 ms  << first change, but no second third and etc.

I used similar configuration in couple of projects and it was fine, everything worked.
I don't know if this information is important, but I'm using Ubuntu 14.04

lomboboo
  • 1,221
  • 1
  • 12
  • 27

1 Answers1

0

After long trying I found a solution for this problem.

I don't know why but this configuration works on Windows, but as appeared on Ubuntu I had to add ** to path of the watched file this part of code:

gulp.task('watch', function () {
    gulp.watch( './**/test.js', gulp.series('es6') );
    console.log('Running watch...');
}); 
lomboboo
  • 1,221
  • 1
  • 12
  • 27
  • I have the same problem in arch linux, and add `**` to path of the watched file not to fix it. sad~ – Roy Dec 05 '16 at 11:32
  • some code like `/** * watch src folder change then run webpack * watch dist folder change then reload browser */ var srcWatcher = gulp.watch('./**/src/**/*',gulp.series('webpack','trim','jekyll',function() { browserSync.reload(); }));`and total code you can see my repo in github, address is https://github.com/dxcqcv/dxcqcv.github.io – Roy Dec 10 '16 at 09:46