Optimize .jpg and .png w/Grunt
The best setup for optimizing .png and .jpg with grunt-contrib-imagemin.
grunt.initConfig({
imagemin: {
png: {
options: {
optimizationLevel: 7
},
files: [
{
expand: true,
cwd: 'project-directory/img/', // cwd is 'current working directory'
src: ['**/*.png'],
dest: 'project-directory/img/compressed/', // Could also match cwd.
ext: '.png'
}
]
},
jpg: {
options: {
progressive: true
},
files: [
{
expand: true, // Tell Grunt where to find our images and where to export them to.
cwd: 'project-directory/img/', // cwd is 'current working directory'
src: ['**/*.jpg'],
dest: 'project-directory/img/compressed/', // Could also match cwd.
ext: '.jpg'
}
]
}
}
});
grunt.registerTask('default', ['imagemin']);
Written by Dennis Gaebel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Grunt
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#