Last active
November 16, 2020 17:47
-
-
Save AkdM/23dd72a3c48c91cfea31e8afa0358d50 to your computer and use it in GitHub Desktop.
Gulp 4 - gulp.watch fix (done callback)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - i "simplified" it even a bit more using an arrow function: