【发布时间】:2021-09-28 20:01:21
【问题描述】:
我想使用这个插件来压缩图片,但是我遇到了构建通过但图片没有被压缩的问题。
我是 webpack 的新手,不明白出了什么问题(也许我需要一个将压缩文件作为文件夹的出口点?)
next.config.js
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
const nextConfig = {
future: {
webpack5: true
},
webpack: (config, options) => {
config.module.rules.push({
test: /\.(jpe?g|png|svg)$/i,
type: "asset",
})
config.plugins.push(new ImageMinimizerPlugin({
minimizerOptions: {
// Lossless optimization with custom option
// Feel free to experiment with options for better result for you
plugins: [
["jpegtran", { progressive: true }],
["optipng", { optimizationLevel: 5 }],
// Svgo configuration here https://github.com/svg/svgo#configuration
[
"svgo",
{
plugins:
{
name: "removeViewBox",
active: false,
},
},
],
],
},
})
)
return config
},
};
module.exports = nextConfig
【问题讨论】:
标签: javascript reactjs webpack next.js