diff --git a/tasks/default.js b/tasks/default.js index 5c70a5b..2d88cdd 100644 --- a/tasks/default.js +++ b/tasks/default.js @@ -5,14 +5,24 @@ module.exports = (gulp, $, pkg) => { const watch = (callback) => { // Fractal automatically detects existing server instance. $.livereload.listen(); - gulp.watch(pkg.gulpPaths.fonts.src, gulp.series('fonts')); - gulp.watch(pkg.gulpPaths.icons.src, gulp.series('icons')); - gulp.watch(pkg.gulpPaths.images.src, gulp.series('images')); - gulp.watch(pkg.gulpPaths.styles.src, gulp.series('styles')); - gulp.watch(pkg.gulpPaths.scripts.src, gulp.series('scripts')); - gulp.watch(pkg.gulpPaths.templates, (files) => { - $.livereload.changed(files); + const tasks = [ + 'fonts', + 'icons', + 'images', + 'styles', + 'scripts', + ]; + tasks.forEach((task) => { + const path = pkg.gulpPaths?.[task]?.src; + if (path) { + gulp.watch(path, gulp.series(task)); + } }); + if (pkg.gulpPaths?.templates) { + gulp.watch(pkg.gulpPaths.templates, (files) => { + $.livereload.changed(files); + }); + } callback(); // Required to stop Gulp throwing async competion error. }; diff --git a/tasks/images.js b/tasks/images.js index a531efe..3891214 100644 --- a/tasks/images.js +++ b/tasks/images.js @@ -2,7 +2,8 @@ module.exports = (gulp, $, pkg) => { // @task: Process and minify images. - const minify = () => { + const minify = async () => { + if (!pkg.gulpPaths?.images?.src) { return false } return gulp.src(pkg.gulpPaths.images.src) .pipe($.imagemin([ $.imagemin.gifsicle({ interlaced: true }), @@ -15,7 +16,7 @@ module.exports = (gulp, $, pkg) => { }; const inlineSvg = async () => { - if (!pkg.gulpPaths.images.inlineSvgs === true) { return false } + if (!pkg.gulpPaths?.images?.inlineSvgs === true) { return false } return gulp.src(pkg.gulpPaths.images.dest + '/**/*.svg') .pipe($.sassvg({ outputFolder: pkg.gulpPaths.styles.srcDir + '/vendor'