imagemin for gruntjs used with watch for grunt not properly watching my files

↘锁芯ラ 提交于 2019-12-24 13:02:48

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/24099367/imagemin-for-gruntjs-used-with-watch-for-grunt-not-properly-watching-my-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!