grunt imagemin不';不要移动未优化的图像
我刚刚在一个项目中注意到这一点: 假设您有大量图像要压缩,它们位于grunt imagemin不';不要移动未优化的图像,image,optimization,gruntjs,grunt-contrib-imagemin,Image,Optimization,Gruntjs,Grunt Contrib Imagemin,我刚刚在一个项目中注意到这一点: 假设您有大量图像要压缩,它们位于imagessrc文件夹中。压缩后,它们会放入图像文件夹,这些就是您在项目中使用的图像 有些图像可能不需要任何优化,我注意到它们保留在源文件夹中,不会在图像中移动,但这带来了一个问题,因为现在,有些图像丢失了,我甚至不知道到底是哪些图像 这是一个错误还是我遗漏了什么 我的配置非常简单: imagemin: { dynamic: { files: [{ expand: true, //
imagessrc
文件夹中。压缩后,它们会放入图像
文件夹,这些就是您在项目中使用的图像
有些图像可能不需要任何优化,我注意到它们保留在源文件夹中,不会在图像中移动,但这带来了一个问题,因为现在,有些图像丢失了,我甚至不知道到底是哪些图像
这是一个错误还是我遗漏了什么
我的配置非常简单:
imagemin: {
dynamic: {
files: [{
expand: true, // Enable dynamic expansion
cwd: '_src/images/', // source images (not compressed)
src: ['**/*.{png,jpg,gif,svg}'], // Actual patterns to match
dest: '_dev/images/' // Destination of compressed files
}]
}
}, //end imagemin
如何将未优化的图像从源移动到距离?您可以在移动目标中所有未优化的图像后立即执行复制任务
使用一些过滤器,以避免覆盖已在dest中的压缩图像
copy: {
unoptimizedImage: {
expand: true,
cwd: '_src/images/',
src: ['**/*.{png,jpg,gif,svg}'],
dest: '_dev/images/'
// Copy if file does not exist.
filter: function (filepath) {
// NPM load file path module.
var path = require('path');
// Construct the destination file path.
var dest = path.join(
grunt.config('copy.main.dest'),
path.basename(filepath)
);
// Return false if the file exists.
return !(grunt.file.exists(dest));
},
},
},