Reputation: 5296
When starting to watch my files, the file system might have changed, when the watch was not on-line. How can I make my watch run the task once at start, after typing in the command gulp dev
?
gulp.task('dev', function () {
gulp.watch('src/**/*', ['scss','inject']);
});
Upvotes: 1
Views: 2535
Reputation: 4441
To run the default
task before watch
:
gulp.task('watch', [ 'default' ], function () {
gulp.watch('themes/my-theme/scss/**/*.scss', ['build-scss']);
gulp.watch('images/*', ['compress-images']);
});
Upvotes: 1
Reputation: 2269
This is all built into gulp-watch, no need to hard code a new task!
Gulp watch includes an option called ignoreInitial
which is true
by default. To run the task once at start simply set this to false
:
gulp.task('dev', { ignoreInitial: false }, function () {
gulp.watch('src/**/*', ['scss','inject']);
});
Upvotes: 3
Reputation: 627
Add this to your gulpfile.js:
gulp.task('dev', ['scss', 'inject', 'watch']);
This way those tasks run first, and then the watch task starts so any changes to the files are accounted for prior to the Watch task starting.
Upvotes: 1