简体   繁体   中英

Webpack, css-minimizer-webpack-plugin vs mini-css-extract-plugin

I am always using mini-css-extract-plugin to optimize CSS. Today I found a new project, css-minimizer-webpack-plugin fromhere , 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 ?

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 ):

 //min-css-extract-plugin goes in the plugins array
 plugins: [
    new MiniCssExtractPlugin({
      filename:
        mode === "production"
          ? "css/[name].[contenthash].chunk.css"
          : "css/[name].css",
    }),
  ],
 //css-minimizer-webpack-plugin goes in the optimization object in minimizer array
 optimization:{
  minimizer: ["...", new CssMinimizerPlugin()],
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM