0

I am using Gulp for watch and sass complier. When I start "watch" first time then "sass" complier runs and its create the css files as per given path. However when I change the .scss files then it doesn't call "sass" complier again. Following is is my these two tasks and variables.

gulp.task('sass', function () {
    gulp.src(config.sassPath)
        .pipe(sass())
        .pipe(gulp.dest(config.cssPath))
        .pipe(livereload());
});

gulp.task('watch', false, function () {
    livereload.listen(8189);
    gulp.src(config.watchPaths)
            .pipe(watch(config.watchPaths, function (event) {
                gulp.start( 'sass', 'js-hint', 'server','test');
                livereload();
            }))
            .pipe(livereload());
});

Following command i use to run "watch" task

gulp watch

I do see "watch" is reloading when I am changing the .scss file. Following is log for this.

[19:49:30] public/sass/html-controls.scss was changed
[19:49:30] /Users/dkuma204/Desktop/Dilip/Projects/OPEN/SourceCode/AWF/OPENApp/application/public/sass/html-controls.scss reloaded.

Not sure what I am missing here. Please help.

joy
  • 3,669
  • 7
  • 38
  • 73

1 Answers1

1

Why it is so complicated? Try this:

gulp.task('watch', false, function () {
    livereload.listen(8189);
    gulp.watch(config.watchPaths,['sass', 'js-hint', 'server', 'test'])       
});

And your every task which requires livereload should have .pipe(livereload()) at the end. You shouldn't use gulp start. Here is one of comment from github discussion:

gulp.start is undocumented on purpose because it can lead to complicated build files and we don't want people using it

niba
  • 2,821
  • 1
  • 19
  • 23
  • Its not working....when i used as you suggested I se gulp is only running "watch" not the other tasks..following is logs.....bash-3.2$ gulp watch [13:14:37] Using gulpfile ~/Desktop/Dilip/Projects/OPEN/SourceCode/AWF/OPENApp/gulpfile.js [13:14:37] Starting 'watch'... [13:14:37] Finished 'watch' after 75 ms – joy Feb 14 '15 at 20:15
  • Are you sure that you changed 'gulp.src' to 'gulp.watch' inside watch task? – niba Feb 14 '15 at 22:41
  • yaa....I simply copy pated your suggested approach..but its not working...seems like child tasks are not starting at all. – joy Feb 14 '15 at 23:10
  • Did you try to change something in your files to check if it will wake one of the tasks which you specified there? I'm asking because your part of log is fine. 'Watch' task should be started and finished. His job was to start 'gulp.watch' which is running under hood. – niba Feb 14 '15 at 23:18
  • surprisingly...using your approach now i am getting following error...seems like some other issue in my gulpfile.js gulp[62773] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-21) – joy Feb 14 '15 at 23:32
  • https://github.com/floatdrop/gulp-watch/issues/7 here guy had the same problem. Try to update your node. – niba Feb 14 '15 at 23:35
  • If you want to start all tasks together with watch task you should do one more task like that: gulp.task('start', ['sass', 'js-hint', 'server', 'test', 'watch']); It will run all build tasks first time and then set the watcher on the files. – niba Feb 14 '15 at 23:37