3

I have updated my image-minimizer-webpack-plugin package from version 2 to 3 and looking at their documentation, I first installed imagemin package and then updated my webpack.config.js. In version 2, I had the following in my config file:

 new ImageMinimizerPlugin({
     minimizerOptions: {
        plugins: [
            ["gifsicle", { interlaced: true }],
            ["jpegtran", { progressive: true }],
            ["optipng", { optimizationLevel: 5 }]
        ],
     },
  })

That throws the following error.

options has an unknown property 'minimizerOptions'

Looking at their documentation, I changed that to this:

new ImageMinimizerPlugin({
        minimizer: {
           implementation: ImageMinimizerPlugin.imageminMinify,
           options: {
               plugins: [
                   ["gifsicle", { interlaced: true }],
                   ["jpegtran", { progressive: true }],
                   ["optipng", { optimizationLevel: 5 }]
               ],
           },
       },
   })

Now I am getting this warning:

"imageminMinify" function do not support generate to "jpg". Please use "imageminGenerate" function.

When I use imageminGenerate instead of imageminMinify, then the images (jpeg files) don't load at all. Any idea what I need to do/change? Thanks in advance.

AkbarB
  • 460
  • 7
  • 24

1 Answers1

0

I got that warning for a file with a ".jpeg" extension, and I was able to fix it by changing the file extension to ".jpg". To support ".jpeg" files without having to manually rename them, you can add this to your webpack config to rename them with file-loader:

  {
    test: /\.jpeg$/,
    use: [
      {
        loader: 'file-loader',
        options: {
          name: `[path][name].jpg`,
        }
      }
    ]
  },
JasonR
  • 401
  • 3
  • 11
  • Did you also replace imageminMinify with imageminGenerate? because the warning that I get is actually saying that the "imageminMinify" function do not support generate to "jpg". It's a jpg thing. – AkbarB May 20 '22 at 15:48
  • No I didn't. For some reason imageminMinify does not recognize that ".jpeg" is the same as ".jpg". After renaming the file, you shouldn't have to make any changes to your ImageMinimizerPlugin config from what you have in your original post (the second code block). – JasonR May 20 '22 at 18:43
  • adding what you suggested and keeping imageminMinify still shows the same warning – AkbarB May 20 '22 at 19:31
  • Renaming the file fixes the issue and removes the warning entirely. Adding that webpack entry doesn't entirely get rid of the warning, but it does fix the issue. Check your output jpg file and you'll see that it has been minified. – JasonR May 20 '22 at 19:56