Reputation: 382
New to gulp. Is there anything wrong with my code? The images should be output to:
assets/images/
but they are not being moved.
My code looks like this:
const FILES_IMAGES = ['./src/components/**/img/*.{svg,jpg,png,gif,jpg}'];
const ASSETS_PATH = '../server/assets/';
const ASSETS_IMG_PATH = ASSETS_PATH + 'images/';
/*
* Images
* --
* Move and Compress images
*/
gulp.task('images', function () {
gulp.src(FILES_IMAGES)
.pipe(imagemin())
.pipe(flatten({ includeParents: 1 }))
.pipe(gulp.dest(ASSETS_IMG_PATH))
;
});
...more code
gulp.task('default', ['watch', 'css', 'css.min', 'images']);
Thanks for your time.
Upvotes: 1
Views: 63
Reputation: 2781
A few things to try here:
Try returning from the task to tell the task system when the task is finished, because gulp.src
is async, more on this SO answer:
gulp.task('images', function () {
return gulp.src(FILES_IMAGES)
.pipe(imagemin())
.pipe(flatten({ includeParents: 1 }))
.pipe(gulp.dest(ASSETS_IMG_PATH));
});
Try sending a string
instead of an array
into gulp.src
, more on this SO answer:
const FILES_IMAGES = './src/components/**/img/*.{svg,jpg,png,gif,jpg}';
array
into gulp.src
(as it is now), try specifying base
directory in gulp.src
, this SO answer might also help:gulp.src(FILES_IMAGES, {base: "."})
I would guess the first point or combination of the first and second points would do the trick.
Upvotes: 2