imagemin for gruntjs与手表一起使用,不能正常观看我的文件 [英] imagemin for gruntjs used with watch for grunt not properly watching my files
问题描述
我想要的是观察者观看任何新添加的图像并仅压缩新添加的图像。我也希望它删除从未压缩文件夹(它是 images / images /
)中删除的图像,也是在压缩文件夹中( images / build /
),但这不会发生。
现在发生的情况是,无论何时添加图像,Grunt都会重新压缩它们所有(如截图所示:
其中我添加了两个新图像,并重新压缩整个文件夹),如果我从未压缩的文件夹中删除图像,grunt会将它们保留在压缩文件夹中。
下面是我的gruntfile的块: p> 观察者部分:
imagemin:{
dynamic:{
files:[{
expand:true,
cwd:'images / images /',
src:['** / *。{png,jpg,gif}'],
dest:'images / build /'
}]
}
},//结束imagemin
images:{
files:['images / images / *。{png,jpg,gif}'],
tasks:['imagemin'],
选项:{
spawn:false,
}
}
我是否需要额外的插件来执行此操作?提前感谢!
您可以使用
- grunt-newer来检测更新的文件: https://github.com/tschaub/grunt-newer
- grunt-删除同步以在两个目录之间同步删除的文件 https://www.npmjs.org/package / grunt-delete-sync
What I would like is the watcher to watch any newly added images and compress ONLY the newly added ones. I would also want it to remove the images I remove from the uncompressed folder (which is images/images/
), also in the compressed one which is (images/build/
), but this doesn't happen.
What happens now is, anytime I add an image, Grunt recompresses them all (as in this screenshot:
where I added two new images, and it recompresses the whole folder) and if I remove an image from the uncompressed folder, grunt keeps them in the compressed one.
Here's chunks of my gruntfile:
the task
imagemin : { dynamic : { files : [{ expand : true, cwd : 'images/images/', src : ['**/*.{png,jpg,gif}'], dest : 'images/build/' }] } }, //end imagemin
the watcher part:
images : { files : ['images/images/*.{png,jpg,gif}'], tasks : ['imagemin'], options : { spawn : false, } }
do I need an additional plugin to do this? thanks in advance!
you can use
- grunt-newer for detecting updated files : https://github.com/tschaub/grunt-newer
- grunt-delete-sync for synchronize deleted files between two directories https://www.npmjs.org/package/grunt-delete-sync
这篇关于imagemin for gruntjs与手表一起使用,不能正常观看我的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!