Webpack 4: How to minify images using Imagemin Plugin

preview_player
Показать описание
Loading images with file-loader and minifying them using imagemin plugin.
Рекомендации по теме
Комментарии
Автор

regex typo missing an escape slash /\.(js|jsx)$/ and /\.(scss|css)/

devn
Автор

thank you so much for the video, it is a great help. I wonder if in webpack 5 can we still use this plugins or there is another option??
Like your videos !!

antoniojimenez
Автор

>>>> the compressing issue in webpack 5 <<<<
Adding it as a rule (not as a plugin) solved the compressing issue for me:

const ImageMinimizerPlugin =

{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: ImageMinimizerPlugin.loader,
options: {
severityError: 'warning', // Ignore errors on corrupted images
minimizerOptions: {
plugins: [
['gifsicle', { interlaced: true }],
['mozjpeg', { progressive: true, quality: 60}],
[
'pngquant',
{
quality: [0.6, 0.8],
},
],
[
'svgo',
{
plugins: [
{
removeViewBox: false,
},
],
},
],
],
},
}
},
]
}

ladyking