您好我的Gulp配置图像有一点问题,我的gulp任务应该缩小资源文件夹中的所有图像,然后将缩小版本放在公共目录中,但只有PNG图像正在正确导出......
gulp.task('images', function() {
gulp.src(assets + 'images/**')
.pipe(imagemin({
progressive: true,
optimizationLevel: 7,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(public + 'images/'));
});
这是我正在运行的任务,我目前正在使用imagemin版本^ 2.4.0
答案 0 :(得分:1)
遇到同样的问题,这是我的配置:
let developmentAssets = "src",
productionAssets = "dist";
module.exports = {
optimize : {
images: {
src: developmentAssets + '/img/**/*.{jpg,jpeg,png,gif,svg}',
options: {
optimizationLevel: 3,
progessive: true,
interlaced: true
}
}
}
};
然后在你的任务中
/*
This is my particular setting to have everything organized
read this amazing gulp tutorial: http://stefanimhoff.de/2014/gulp-tutorial-12-optimize-css-javascript-images-and-html/
*/
config = require('./gulp/config'),
configImg = config.optimize.images,
.pipe(imagemin(configImg.options))
希望它有所帮助。