What you can do with grunt
- Gruntでimageoptim, imageminを実行
- 指定したフォルダの追加、変更をwatchして自動的に画像最適化可能
I first install the following plug-ins
- grunt-conrib-imagemin (https://github.com/gruntjs/grunt-contrib-imagemin)
- grunt-imageoptim (https://github.com/JamieMason/grunt-imageoptim)
- grunt-contrib-livereload (https://github.com/gruntjs/grunt-contrib-livereload)
- grunt-contrib-watch (https://github.com/gruntjs/grunt-contrib-watch)
It performs the task if you will be monitoring the filepath set by the task of imagemin and imageoptim, changes and additions were made.
changedFiles = Object.create(null);
onChangeImage = grunt.util._.debounce(function() {
var filesArray, paths;
paths = Object.keys(changedFiles);
filesArray = [];
paths.forEach(function(path) {
filesArray.push({
src: path,
dest: path
});
});
grunt.config(['imageoptim', 'feature', 'files'], filesArray);
grunt.config(['imagemin', 'ondemand', 'files'], filesArray);
changedFiles = Object.create(null);
}, 200);
Install from here.
http://imageoptim.com/
The MIT License (MIT)