我希望您能帮助翻译一下关于IT技术的内容。需要翻译的内容为:我想要像TinyPNG一样压缩图像,并将压缩后的图像保存在dist文件夹中。我使用webpack 4,并找到了imagemin-webpack插件,但我不知道该用插件还是加载器?请帮忙配置此任务。
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"),
]
};
这是我的配置文件。运行构建命令后,图像没有任何变化。