Home

Awesome

@rsbuild/plugin-css-minimizer

An Rsbuild to customize the CSS minimizer, switch to cssnano or other tools for CSS compression.

@rsbuild/plugin-css-minimizer internally integrates css-minimizer-webpack-plugin.

<p> <a href="https://npmjs.com/package/@rsbuild/plugin-css-minimizer"> <img src="https://img.shields.io/npm/v/@rsbuild/plugin-css-minimizer?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> </a> <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" /> </p>

Usage

Install:

npm add @rsbuild/plugin-css-minimizer -D

Add plugin to your rsbuild.config.ts:

// rsbuild.config.ts
import { pluginCssMinimizer } from "@rsbuild/plugin-css-minimizer";

export default {
  plugins: [pluginCssMinimizer()],
};

Options

pluginOptions

Used to customize the options of css-minimizer-webpack-plugin.

The value of pluginOptions will be merged with the default options inside the plugin using Object.assign and then passed to the css-minimizer-webpack-plugin. You can refer to the README documentation of css-minimizer-webpack-plugin to explore all available options.

const defaultOptions = {
  minify: CssMinimizerWebpackPlugin.cssnanoMinify,
  minimizerOptions: {
    preset: [
      "default",
      {
        mergeLonghand: false,
      },
    ],
  },
};
pluginCssMinimizer({
  pluginOptions: {
    minimizerOptions: {
      preset: require.resolve("cssnano-preset-simple"),
    },
  },
});
pluginCssMinimizer({
  pluginOptions: (options) => {
    options.minimizerOptions = {
      preset: require.resolve("cssnano-preset-simple"),
    };
  },
});
import {
  pluginCssMinimizer,
  CssMinimizerWebpackPlugin,
} from '@rsbuild/plugin-css-minimizer';

pluginCssMinimizer({
  pluginOptions: {
    minify: CssMinimizerWebpackPlugin.cleanCssMinify,
    minimizerOptions: {
      level: {
        1: {
          roundingPrecision: "all=3,px=5",
        },
      },
    },
  },
}),

License

MIT.