Skip to content

Commit f8571d2

Browse files
committed
Prevent build errors from stopping the watch process
1 parent 085c9c4 commit f8571d2

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

gulpfile.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ var paths = {
2121
pug: './index.pug'
2222
}
2323

24-
//
25-
// Internal watch triggers
26-
//
27-
28-
gulp.task( '_watch', function() {
29-
gulp.watch( paths.styles.watch, gulp.series( 'default' ) )
30-
gulp.watch( paths.pug, gulp.series( 'pug' ) )
31-
gulp.watch( paths.config, gulp.series( 'pug' ) )
32-
gulp.watch( paths.images, gulp.series( 'pug' ) )
33-
} )
34-
3524
//
3625
// Build style.css
3726
//
@@ -74,6 +63,23 @@ gulp.task( 'pug', function() {
7463
.pipe( gulp.dest( './' ) )
7564
} )
7665

66+
//
67+
// Watch file changes and trigger build tasks
68+
//
69+
70+
gulp.task( '_watch', function() {
71+
// Task watch wrapper that prevents an error from bubbling up and stopping the watch process
72+
function gulpWatch( globs, fn ) {
73+
gulp.watch( globs, fn )
74+
.on( 'error', function() { this.emit('end') } )
75+
}
76+
77+
gulpWatch( paths.styles.watch, gulp.series( 'default' ) )
78+
gulpWatch( paths.pug, gulp.series( 'pug' ) )
79+
gulpWatch( paths.config, gulp.series( 'pug' ) )
80+
gulpWatch( paths.images, gulp.series( 'pug' ) )
81+
} )
82+
7783
//
7884
// The default task is to build the product
7985
//

0 commit comments

Comments
 (0)