A PostCSS plugin to replace class names based on a customizable renaming scheme.
postcss-rename makes it possible to rename CSS class names in the generated
stylesheet, which helps reduce the size of the CSS that is sent down to your
users. It's designed to be used along with a plugin for a build system like
Webpack that can rewrite HTML templates and/or references in JS. If you write
such a plugin, let us know and we'll link it here!
The renaming strategy to use:
"none": Don't change names at all. This is the default strategy.
"debug": Add an underscore at the end of each name. This is useful for
"minimal": Use the shortest possible names, in order of appearance: the
.a, the second to
.b, and so on.
This can also be a function that takes a CSS name (the full name in by-whole mode and the part in by-part mode) and returns its renamed value.
Whether to rename in "by-whole mode" or "by-part mode".
"whole": Rename the entire name at once, so for example
.a. This is the default mode.
"part": Rename each hyphenated section of a name separately, so for example
.tall-image might become
A string prefix to add before every renamed class. This applies even if
strategy is set to
In by-part mode, the prefix is applied to the entire class, but it isn't included in the output map.
An array (or other
Iterable) of names that shouldn't be renamed.
Whether to rename ID selectors as well as class selectors. Defaults to
A callback that's passed a map from original class names to their renamed
equivalents, so that an HTML template or JS class references can also be
In by-part mode, this contains separate entries for each part of a class name. It doesn't contain any names that weren't renamed because of
Disclaimer: This is not an officially supported Google product.