Sharing is caring!

Plugin to compress images with imagemin

This is a simple plugin that uses Imagemin to compress all images in your project.


npm install imagemin-webpack-plugin

Requires node >=4.0.0

Example Usage

var ImageminPlugin = require('imagemin-webpack-plugin').default
// Or if using ES2015:
// import ImageminPlugin from 'imagemin-webpack-plugin'

module.exports = {
  plugins: [
    // Make sure that the plugin is after any plugins that add images
    new ImageminPlugin({
      disable: process.env.NODE_ENV !== 'production', // Disable during development
      pngquant: {
        quality: '95-100'

Working with copy-webpack-plugin:

module.exports = {
  plugins: [
    // Copy the images folder and optimize all the images
    new CopyWebpackPlugin([{
      from: 'images/'
    new ImageminPlugin({ test: /\.(jpe?g|png|gif|svg)$/i })

Note the order of the plugins matters. ImageminWebpackPlugin must be placed after CopyWebpackPlugin (or any other plugins that deal with images) in plugins array.

Subscribe to the Newsletter

Get our latest news,tutorials,guides,tips & deals delivered to your inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.