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

442 Views Asked by At

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:

enter image description here

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

There are 1 best solutions below

1
On BEST ANSWER

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