Now for something super amazing. Instead of running the gulp task explicitly, lets have gulp run our tasks when the files change.
First reorganize some of our tasks:
- Rename default task to css.
- Create a new default task to run css, ‘javascript’, and ‘homepage’ tasks.
gulpfile.js
1234567891011
...gulp.task('css',['clean'],function(){console.log("Concat, move, and minify all the css files in styles folder");returngulp.src("contents/styles/**.css").pipe(concat('main.min.css')).pipe(cssmin()).pipe(gulp.dest('build/styles'));});...gulp.task('default',['css','homepage','javascript']);...
Next create our file watching task. Could you guess what?… there isn’t a plugin for this. It is just part of gulp.
We will create a gulp watch task to watch our contents folder and run our default task on file change.