Repository navigation
Breaking changes
- Node.js 22 or newer is required.
- ESM and CommonJS builds: the package ships both with an
exportsmap and types for each.require('postcss-replace-values')returns the plugin directly, remove.defaultif you used it. The TypeScript sources (lib/) are no longer published. - Whole token matching: keys only match whole values, not parts of them.
redno longer turnsdarkredintodarkblue,5pxno longer turns15pxinto19px. - Strings and
url()are left untouched:content: "#000"andurl(icons.svg#fab)keep their value (before, the URL fragment became#ffaabb). To replace a whole string or URL, use it as the key, including the quotes:'"Open Sans"': '"Inter"'. - Single pass: all keys are replaced in one pass instead of one after another, a replacement is never replaced again.
{ '#000': '#a00', '#a00': '#0a0' }now turns#000into#a00instead of#0a0. When two keys match at the same position, the first one wins. - Hex notation is kept: other hex colors in a changed declaration are no longer rewritten to their long, lowercase form.
background: #FFF linear-gradient(#000, #ABC)with{ '#000': '#a00' }givesbackground: #FFF linear-gradient(#a00, #ABC)instead ofbackground: #ffffff linear-gradient(#a00, #aabbcc). - Selector values skip declarations outside of rules, like inside
@font-face. Before, the selector was tested against the string"undefined". - Options are validated: an empty key, a replacement that is no string or
{ value: string }, or a selector that is no RegExp or string now throws when the plugin is created. Before, an invalid replacement wroteundefinedinto the CSS. Error messages are prefixed withpostcss-replace-values:.
New
- Swap values:
{ '#000': '#fff', '#fff': '#000' }swaps both colors, also within the same declaration. ignoreCaseoption: match keys that are no hex color in any case, e.g.Arialalso matchesarial. Works for non-ASCII letters too (ämatchesÄ).- Optional
selector:{ value: '#a00' }replaces everywhere, andselectoris typed to accept a string as well as a RegExp.
Fixes
- No more endless loops: the build no longer hangs when a replacement contains its key (
{ 'Arial': 'Arial Black' }), contains$&, or when values are swapped. - Replacements are inserted literally:
$&and other special replacement patterns in a value are not expanded. - Installs cleanly: 3.0.2 failed to load with
Cannot find module 'hex-color-regex'unless that package happened to be installed.
Internal
- No runtime dependencies anymore (
color-shorthand-hex-to-six-digit,lodash.clonedeep,lodash.isplainobjectandstring.prototype.replaceallare removed).postcssstays a peer dependency (^8.0.0). - Built with tsdown, tested with vitest, linted with oxlint. CI tests on Node.js 22, 24 and 26.
- Releases are published with npm trusted publishing and provenance.
See the upgrade guide in the README.
Full Changelog: v3.0.2...v4.0.0