I am always using mini-css-extract-plugin
to optimize CSS. Today I found a new project, css-minimizer-webpack-plugin
from here, seems like this project do the same thing as mini-css-extract-plugin
.
What is the advantage of css-minimizer-webpack-plugin
? I read the docs and article from google, seems no one is talking about it? Should I use css-minimizer-webpack-plugin
to replace the mini-css-extract-plugin
?
Advertisement
Answer
They are not for the same purpose. css-minimizer-webpack-plugin
is used to compress the css files produced by min-css-extract-plugin
. Here is how thy are used (I am in webpack.config.js
):
JavaScript
x
14
14
1
//min-css-extract-plugin goes in the plugins array
2
plugins: [
3
new MiniCssExtractPlugin({
4
filename:
5
mode === "production"
6
? "css/[name].[contenthash].chunk.css"
7
: "css/[name].css",
8
}),
9
],
10
//css-minimizer-webpack-plugin goes in the optimization object in minimizer array
11
optimization:{
12
minimizer: ["...", new CssMinimizerPlugin()],
13
}
14