Search code examples
laravelgulplaravel-elixir

gulp watch on gulpfile.js itself


I'd like to not only have gulp watch watch for changes to specified files, but also to the gulpfile.js itself. Notably, I'm using Laravel and its Elixir asset management tool, which wraps Gulp.

I came across this link which seems to be exactly what I need but when I implement it and then type either gulp watch or gulp and then make changes to my gulpfile those changes aren't reflected.

I'm pretty sure I need to add something to the elixir but not sure what. I have the following for bower but probably need something similar for watch.

Here's the relevant contents of my gulpfile:

/*gulpfile.js*/
gulp.slurped = false; // step 1

gulp.task("watch", function(){

    if(!gulp.slurped){ // step 2
        gulp.watch("gulpfile.js", ["default"]);
        //gulp.watch("etc...");
        gulp.slurped = true; // step 3
    }

});

gulp.task("default", ["some-task", "another-task", "watch"]);

gulp.task('bower', function() {
  return bower();
});

elixir(function(mix) {
  // Run bower install
  mix.task('bower');
  //mix.task('default'); //uncommenting this causes an error when running "gulp"
  //mix.task('watch'); //uncommenting this causes an error when running "gulp"

  // all other elixir.mix tasks...
  mix.copy('resources/assets/js/**', 'public/js');

Solution

  • gulper is one possible answer: https://github.com/anatoo/gulper

    So instead of running gulp watch you can run gulper watch