From e370d9a18fe455036cbb8b315bcaa3399d9d6c30 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 19 Feb 2018 21:29:16 -0600 Subject: [PATCH] wrapping imagemin in a watcher to insure it finishes Addresses issue #414 and similar where imagemin results in browsersync looping --- gulpconfig.json | 2 ++ gulpfile.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gulpconfig.json b/gulpconfig.json index 2280ad8..14bdd59 100644 --- a/gulpconfig.json +++ b/gulpconfig.json @@ -11,6 +11,8 @@ "paths" : { "js": "./js", "css": "./css", + "img": "./img", + "imgsrc": "./src/img", "sass": "./sass", "node": "./node_modules/", "bower": "./bower_components/", diff --git a/gulpfile.js b/gulpfile.js index 6cd8262..ee35432 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -101,16 +101,25 @@ gulp.task('watch', function () { gulp.watch([paths.dev + '/js/**/*.js','js/**/*.js','!js/theme.js','!js/theme.min.js'], ['scripts']); //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: // gulp imagemin // Running image optimizing task gulp.task('imagemin', function(){ - gulp.src('img/src/**') + gulp.src(paths.imgsrc + '/**') .pipe(imagemin()) - .pipe(gulp.dest('img')) + .pipe(gulp.dest(paths.img)) });