0

I'm new to gulp and i'm trying to watch jade and less files and clean the build directory before moving the new files. Somehow the task works for the first time i change a file and then it doesn't keep watching. I have found many different solutions but none of them worked for me. Here are my watch tasks:

gulp.task('watch', function() {
   gulp.watch(config.lessDir + '/**.less', ['css']);
   gulp.watch(config.jadeDir + '/**.jade', ['jade']);
});

gulp.task('jade', function() {
   del.sync(['build/**.html']);

   return gulp.src(config.jadeDir + '/**.jade')
   .pipe(jade({ pretty: true }))
   .pipe(gulp.dest('./build'));
});

gulp.task('css', function() {
   del.sync(['build/css/**.*']);

   return gulp.src(config.lessDir + '/**.less')
   .pipe(less())
   .pipe(gulp.dest('./build/css'))
   .pipe(minifyCSS())
   .pipe(extReplace('.min.css'))
   .pipe(gulp.dest('./build/css'));
});

With plumber i get the error "undefined is not a function".

Edit: Seems like del is not the problem but rather the pipelines handling the jade/less files.

5
  • A note: if del is this, then del.sync does not accept a callback. The cb will probably never get called. Now this may confuse Gulp that, when the task function receives an argument, it expects this argument to be called to know that the task finished. Actually I do not know which takes precedence to determine task completion, the callback argument or the returned stream, but using both is at least confusing if not error prone. Commented Sep 7, 2015 at 11:27
  • Thank you. I already changed that. My problem is still present though. Commented Sep 7, 2015 at 14:22
  • can you remove the del part and see if the issue still persists? Commented Sep 8, 2015 at 3:52
  • Already tried that, the issue seems to be somewhere in the pipeline of processing the less files. Edit: The issue only occurs if i rename one of the files in the less folder. The new CSS files are generated and then gulp stops watching the folder. Commented Sep 8, 2015 at 16:27
  • So for everyone having the same issue: DONT use absolute paths ('./less/bla') for example. gulp.watch only takes relative paths as it seems ('less/bla'). Now it works like a charm. Commented Sep 8, 2015 at 20:43

1 Answer 1

1

For everyone having the same issue: gulp.watch only detects new or deleted files if you use relative paths. For example: use "less" instead of "./less". Now everything should work like a charm.

Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to stack overflow! You can (and should) mark your own answer as correct to make the question show up as solved instead of still waiting for answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.