Skip to content

Instantly share code, notes, and snippets.

@AkdM
Last active November 16, 2020 17:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkdM/23dd72a3c48c91cfea31e8afa0358d50 to your computer and use it in GitHub Desktop.
Save AkdM/23dd72a3c48c91cfea31e8afa0358d50 to your computer and use it in GitHub Desktop.
Gulp 4 - gulp.watch fix (done callback)
// This tricks prevents the reload-only-once 'new' feature
// of Gulp 4, when using gulp.watch
'use strict';
var gulp = require('gulp'),
sass = require('gulp-sass'),
electron = require('electron-connect').server.create();
// You should also add a 'clean' task to clean the dist folder
// I removed it because it is not needed in this example
gulp.task('serve', function () {
electron.start();
gulp.watch('app/**/*.sass', gulp.series('styles', reload)); // <-- The trick is here, you need to create function with the done callback
// Here are some more examples in case you're not sure:
//gulp.watch('app/**/*.pug', gulp.series('views', reload));
//gulp.watch('app/**/*.ts', gulp.series('scripts', reload));
});
// See? Simple.
function reload(done) {
electron.reload();
done();
}
gulp.task('default', gulp.series('styles', 'serve'));
@florianb
Copy link

Thanks - i "simplified" it even a bit more using an arrow function:

gulp.watch('app/**/*.sass', gulp.series('styles', done => {
  electron.reload();
  done();
}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment