使用 cssnano 优化和压缩 CSS

安装

  1. npm i -D css-minimizer-webpack-plugin

配置

文件:webpack.config.js

  1. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  2. const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
  3. module.exports = {
  4. module: {
  5. rules: [
  6. {
  7. test: /.s?css$/,
  8. use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
  9. },
  10. ],
  11. },
  12. // 优化
  13. optimization: {
  14. minimizer: [
  15. new CssMinimizerPlugin(),
  16. ],
  17. },
  18. };