0

I'm getting the same problem as this guy.

My terminal looks like:

$ gulp watch
[23:59:03] Using gulpfile gulpfile.js
[23:59:03] Starting 'watch'...
[23:59:03] Finished 'watch' after 8.68 ms

http://jsbin.com/poxoke/1/edit?js

Why can't I get it to watch for file changes? Why does it end so quickly?

Thanks!

Community
  • 1
  • 1
heyjohnmurray
  • 205
  • 3
  • 14
  • Are you positive it's not still watching? It does say "Finished watch" in-between when watch is doing stuff. – itamar Feb 24 '15 at 05:09
  • Well, I've added gulp to another project before and when it watched then it wouldn't say "finished" and whenever I made a change to the sass it'd run the 'sass' command and you'd see activity in terminal. So, yes @itamar, I'm as certain as I can be. – heyjohnmurray Feb 24 '15 at 05:11
  • It's not finished, it just says that... mine is the same, but as soon as you make a change, say in the CSS. I see my console statements print saying what file was compiled. – Leon Gaban Feb 24 '15 at 16:52

1 Answers1

0

you could try adding gulp-util

var util= require('gulp-util');

and then inside your sass task add the line to report any error, if this is one, to console output.

gulp.task('sass', function () {
  return gulp.src('assets/scss/*.scss')
    .pipe(sourcemaps.init())
    .pipe(sass({
        includePaths: ['sass'].concat(bourbon),
        outputStyle: 'compressed'
    }))
    .on('error', util.log)
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('assets/css'));
});

If gulp-sass throws an error this can get "consumed" by the pipe but still causes the whole stream to terminate. So if you add the line to explicitly catch them and then log them out you can see if this is in fact the case.

Your watch task is dependant on the 'sass' task and if it fails your task ends.

gulp.task('watch', function(){
    gulp.watch('assets/scss/*.scss', ['sass']);
});

My current rule for this is:

gulp.task('sass', function () {
  var src = path.join('src', 'scss', '*.scss');
  var dst = path.join('public', 'css');
  var config = {
    errLogToConsole: true,
    outputStyle: 'compressed',
    sourceComments: false
  };
  return gulp.src(src)
         .pipe(sourcemaps.init())
         .pipe(sass(config)).on('error', util.log)
         .pipe(concat('style.css')).on('error', util.log)
         .pipe(sourcemaps.write('.'))
         .pipe(gulp.dest(dst));
});

And that all works fine

My output is this: [05:49:27] Using gulpfile F:\Projects\Upload\gulpfile.js [05:49:27] Starting 'watch'... [05:49:29] Finished 'watch' after 1.98 s

but Gulp does not return to the command line, the cursor still keeps flashing away and when I update SASS files the code runs again and the updates are made to the CSS

Code Uniquely
  • 6,356
  • 4
  • 30
  • 40
  • there's no error caught by util. thanks for the suggestion though. same outcome as before in terminal. – heyjohnmurray Feb 24 '15 at 05:27
  • The only other difference between your set-up and the one I've added to my answer is that I write .pipe(sourcemaps.write('.')) and a couple of additional configuration options. And the other way around, you use the IncludePaths configuration option and I don't. I included my set-up so you have something to reference - It happily working day in day out, all day long. It might help you track down the error. – Code Uniquely Feb 24 '15 at 05:44
  • where is path defined in all this? i see the path.join references but no instantiation. – heyjohnmurray Feb 24 '15 at 05:57
  • Added at the top of my gulpfile.js just after i require('gulp') I Just add a var path = require(path); – Code Uniquely Feb 24 '15 at 05:58
  • current code. http://jsbin.com/liboyo/1/edit?js still the same result. it returns me to command line. – heyjohnmurray Feb 24 '15 at 06:04
  • just copied your file and ran it on my dev machine and it works fine, I did strip out everything other than the SASS part http://jsbin.com/qusewoleci/1/edit?js – Code Uniquely Feb 24 '15 at 06:16