当我在我的 webpack 中加载图像时,我想优化该图像并制作该图像的 webp。我使用带有最小化器和生成器选项的 image-minimizer-webpack-plugin,但它只生成 webp,原始版本被删除
optimization: {
minimize: true,
minimizer: [
"...",
new ImageMinimizerPlugin({
generator: [
{
preset: "webp",
implementation: ImageMinimizerPlugin.imageminGenerate,
options: {
plugins: ["imagemin-webp"],
},
},
{
type: "asset",
implementation: ImageMinimizerPlugin.imageminGenerate,
options: {
plugins: ["imagemin-webp"],
},
},
],
minimizer: {
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
plugins: [
['gifsicle', { interlaced: true }],
['jpegtran', { progressive: true }],
['optipng', { optimizationLevel: 5 }],
[
'svgo',
{
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
],
},
],
],
},
},
}),
],
},