我需要像TinyPNG一样压缩图像并将压缩图像保存在dist文件夹中。 我使用webpack 4并找到了imagemin-webpack.But我不明白用什么:插件或加载器? 请帮助完成此任务的配置。
let path = require('path');
let ExtractTextPlugin = require("extract-text-webpack-plugin");
let {imageminLoader} = require("imagemin-webpack");
let imageminGifsicle = require("imagemin-gifsicle");
let conf = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, './dist/'),
filename: 'main.js',
publicPath: 'dist/'
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
minimize: true,
sourceMap: true
}
}
]
})
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: "file-loader"
},
{
loader: imageminLoader,
options: {
cache: true,
bail: false,
imageminOptions: {
plugins: [imageminGifsicle()]
},
name: "[hash]-compressed.[ext]"
}
}
]
}
]
},
plugins: [
new ExtractTextPlugin("styles.css"),
]
};
这是我的配置文件。运行构建命令后,图像没有任何反应。