Có thể xem nhiều tệp/thư mục nhưng chỉ tối ưu hóa một tệp bằng grunt-contrib-imagemine và grunt-contrib-watch không?Grunt imagemin - xem nhiều tập tin/thư mục tối ưu hóa tập tin duy nhất?
tôi đã cố gắng như thế này: (một phần của gruntfile)
imagemin: {
dist: {
cwd: 'images/modules',
files: ['images/modules/**/*.{png,jpg,gif}'],
dest: 'images/modules'
}
},
watch: {
images: {
files: ['images/modules/**/*.{png,jpg,gif}'],
tasks: ['imagemin'],
options: {
spawn: false,
}
}
}
grunt.event.on('watch', function(action, filepath, target) {
if (grunt.file.isMatch(grunt.config('watch.images.files'), filepath)) {
grunt.config('imagemin.dist.src', [filepath]);
}
});
Nhưng nó không hoạt động. Nó trả về:
Running "imagemin:dist" (imagemin) task
Verifying property imagemin.dist exists in config...OK
Files: [no src] -> images/modules
Options: optimizationLevel=7, progressive, pngquant=false
Options: optimizationLevel=7, progressive, pngquant=false
Warning: path must be a string
Bất kỳ ý tưởng nào? Cảm ơn bạn.