javascript - Using Grunt, Newer and Watch to optimize a bunch of images -


i started today getting used grunt. wanted create grunt package? script? module? task? optimizes images uploaded folder (uploads/ ... it's wordpress installation).

after fiddling, i've create small gruntfile.js

module.exports = function(grunt) {     grunt.initconfig({         imagemin: {              dynamic: {                  files: [{                     expand: true,                     cwd: '../uploads',                      src: ['**/*.{png,jpg,gif}'],                     dest: '../uploads'                 }]             }         },         watch: {             options: { nospawn: true},             scripts: {                 files: ['../uploads/**/*.{png,jpg,gif}'],                 tasks: ['newer:imagemin']             }         }     });      grunt.loadnpmtasks('grunt-contrib-imagemin');     grunt.loadnpmtasks('grunt-contrib-watch');     grunt.loadnpmtasks('grunt-newer');     grunt.registertask('default', ['newer:imagemin','watch']); } 

it seems work fine, task first tries optimize existing images (if not optimized), after watch ensures optimize task runs whenever picture in uploads folder changes, newer ensures new files optimized.

because i'm started grunt, there missed? happen if upload takes long time, watch start task on unfinished file , how prevent it?


Comments