Search code examples
gulpgulp-watchlivereload

Using livereload() directly with watch?


gulp.task('live', function() {
    // listen for changes
    livereload.listen();

    // watch less files in src (to start just type gulp in the src directory)
    gulp.watch('public/css/**/*.less', ['src-less-to-css', 'src-less-to-css-ie8', 'src-less-to-css-ie9']);
    gulp.watch('public/**/*', livereload()); // <--- this ain't working

    // configure nodemon
    nodemon({
        // the script to run the app
        script: 'app.js',
        ext: 'js',
        ignore: ['public/**/*']
    }).on('restart', function(){
        // when the app has restarted, run livereload.
        gulp.src('app.js')
            .pipe(livereload())
            .pipe(notify('Reloading page, please wait...'));
    })
});

So I'd like to invoke the livereload() method whenever a file inside the public directoy is changed, doesnät matter which file, anything and everything.

I was hoping for a simple solution like the above.


Solution

  • Ok found a cheap solution, don't know if it's the best though.

    gulp.watch('public/**/*', ['reload']);
    

    This function:

    // used by the public watch
    gulp.task('reload', function () {
        return gulp.src('app.js')
            .pipe(livereload());
    });