Must pass a task to default cache.proxy
markgoodyear opened this issue · comments
I'm trying to follow the example from the readme to cache image files and only compress changed/new ones.
I'm getting the error: Must pass a task to default cache.proxy
gulp.task('imagemin', function() {
gulp.src('src/images/**/*')
.pipe(cache.proxy(imagemin(), {
key: makeHashKey,
success: function (imageFile) {
return imageFile;
},
value: function (imageFile) {
return {
imagemin: imageFile.imagemin
};
}
}))
.pipe(imagemin())
.pipe(gulp.dest('dist/assets/img'));
});
function makeHashKey(file) {
return file.contents.toString('utf8');
}
I'm not fully sure what I'm doing so I'm probably missing something. I tried using the example directly and I got the same error.
Any help appreciated,
Cheers!
Sorry, that's a problem with the docs probably. Try passing as a task: imagemin()
option, a la:
gulp.task('imagemin', function() {
gulp.src('src/images/**/*')
.pipe(cache.proxy('imagemin', {
task: imagemin(),
key: makeHashKey,
success: function (imageFile) {
return imageFile;
},
value: function (imageFile) {
return {
imagemin: imageFile.imagemin
};
}
}))
.pipe(imagemin())
.pipe(gulp.dest('dist/assets/img'));
});
function makeHashKey(file) {
return file.contents.toString('utf8');
}
The string is just the folder where these cache files are held and actually is optional.
And also, no need to pipe to imagemin() after the proxy.
The proxy will call the imagemin task if it doesn't get a cache hit.
Updated documentation to match actual implementation.
Brilliant, all working great now!
Im not sure the use of defining the name in cache.proxy
:
.pipe(cache.proxy('imagemin', {
as above and .pipe(cache.proxy({
as in the readme. I tested both and both work fine.
Cheers.
Awesome. The name thing is a way to make sure other tasks don't share the same cache directory. I agree the it's kind of convoluted, I'll probably take it out of the example in the docs.
Thanks for the feedback.