wrapping imagemin in a watcher to insure it finishes

Addresses issue #414 and similar where imagemin results in browsersync looping
This commit is contained in:
Sam 2018-02-19 21:29:16 -06:00
parent d8b45f064d
commit e370d9a18f
2 changed files with 14 additions and 3 deletions

View File

@ -11,6 +11,8 @@
"paths" : { "paths" : {
"js": "./js", "js": "./js",
"css": "./css", "css": "./css",
"img": "./img",
"imgsrc": "./src/img",
"sass": "./sass", "sass": "./sass",
"node": "./node_modules/", "node": "./node_modules/",
"bower": "./bower_components/", "bower": "./bower_components/",

View File

@ -101,16 +101,25 @@ gulp.task('watch', function () {
gulp.watch([paths.dev + '/js/**/*.js','js/**/*.js','!js/theme.js','!js/theme.min.js'], ['scripts']); gulp.watch([paths.dev + '/js/**/*.js','js/**/*.js','!js/theme.js','!js/theme.min.js'], ['scripts']);
//Inside the watch task. //Inside the watch task.
gulp.watch('./img/**', ['imagemin']) gulp.watch(paths.imgsrc + '/**', ['imagemin-watch']);
});
/**
* Ensures the 'imagemin' task is complete before reloading browsers
* @verbose
*/
gulp.task('imagemin-watch', ['imagemin'], function(done) {
browserSync.reload();
done();
}); });
// Run: // Run:
// gulp imagemin // gulp imagemin
// Running image optimizing task // Running image optimizing task
gulp.task('imagemin', function(){ gulp.task('imagemin', function(){
gulp.src('img/src/**') gulp.src(paths.imgsrc + '/**')
.pipe(imagemin()) .pipe(imagemin())
.pipe(gulp.dest('img')) .pipe(gulp.dest(paths.img))
}); });