Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G4 - Watch only running once #1626

Closed
joe-watkins opened this issue Apr 30, 2016 · 5 comments
Closed

G4 - Watch only running once #1626

joe-watkins opened this issue Apr 30, 2016 · 5 comments

Comments

@joe-watkins
Copy link

Gulp 4 newbie here. I'm having trouble firing off a series of tasks using watch in Gulp 4. Anyone see an issue with this?

gulp.watch(['scripts/**/*.js','!scripts/main.min.js'], gulp.series(buildScripts,reload));

The darn thing only runs once.

@TrySound
Copy link
Contributor

TrySound commented Apr 30, 2016

@joe-watkins dup of #1624

@phated
Copy link
Member

phated commented Apr 30, 2016

More specifically, an exact duplicate of #1623 - please see my response at #1623 (comment)

Your reload function is most likely a method pulled directly from BrowserSync but it isn't an async function. The reason this was working at all (though incorrectly) was due to inconsistencies in our API.

@phated phated closed this as completed Apr 30, 2016
@phated
Copy link
Member

phated commented Apr 30, 2016

Docs for gulp.watch in the 4.0 branch have been updated for more clarity.

@joe-watkins
Copy link
Author

joe-watkins commented May 6, 2016

@phated @TrySound Thanks very much for the help! ;)

Here is what I ended up doing to solve the issue w/Browsersync and Gulp 4.

Removed the reload from the watch:

gulp.watch(['scripts/**/*.js','!scripts/main.min.js'], buildScripts);

Added .pipe(browserSync.stream()) to my task:

function buildScripts(){
      return gulp.src(appDefaults.mainJsFiles)
        .pipe(concat(appDefaults.jsMin))
        .pipe(uglify())
        .pipe(gulp.dest(appDefaults.jsDir))
        .pipe(browserSync.stream()) // <!-- this is the line added
        .pipe(notify({message: 'JS Compiled'}));
    }

@haluvibe
Copy link

haluvibe commented Jul 7, 2016

Wrap the browserSync.reload() in a function with a done callback :


function reload(done) {
  browserSync.reload();
  done();
}

gulp.watch(['scripts/**/*.js','!scripts/main.min.js'], gulp.series(buildScripts, reload));

fusionstrings added a commit to fusionstrings/polymer-bootlicker that referenced this issue Jul 11, 2016
Gulp watch fails after first run. this is a fix for that. Reference is as follows.
gulpjs/gulp#1626 (comment)
@gulpjs gulpjs locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants