'Webpack ImageMinimizerPlugin "imageminMinify" function do not support generate to "jpg"
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.
Solution 1:[1]
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`,
}
}
]
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | JasonR |