所有文件都经过处理,因为 gulp-changed ( 要么 gulp-newer )在您的任务中检查名称为的文件的更改 gulp.src(img_src) 。 而且因为有 img_dest dir没有原始名称的文件,任务将被执行的所有文件 img_src DIR。
gulp-changed
gulp-newer
gulp.src(img_src)
img_dest
img_src
要解决此问题,可以使用暂存目录来修改文件。 例如:
1)创建新目录'_resize'。
2)修改gulpfile.js:
var img_resize = '_resize'; gulp.task( 'resize-xl', function () { return gulp.src( img_src ) .pipe( changed( img_resize ) ) // add here your image plugins: imageResize, imagemin, .. // save the modified files with original names on '_resize' dir .pipe( gulp.dest( img_resize ) ) .pipe( rename( { suffix: '-2048' } ) ) // save the modified files with new names on destanation dir .pipe( gulp.dest( img_dest ) ); } );
首次运行后,此任务将仅处理新文件和已更改的文件
你也可以在管道之前重命名你的文件 变 插件,以便插件获取具有新名称的源文件:
gulp.task( 'resize-xl', function () { return gulp.src( img_src ) // change name first .pipe( rename( { suffix: '-2048' } ) ) .pipe( changed( img_dest ) ) // add here your image plugins: imageResize, imagemin, .. .pipe( gulp.dest( img_dest ) ); } );