PostCSS plugin using short-css-vars to shorten the names of CSS variables in stylesheets.
CSS variables are renamed with a unique hash that is consistent across processed files. This allows you to have common style files that reference variables with varying values defined in theme files.
$ npm install postcss-short-css-vars --save-dev
See the PostCSS docs for examples on how to use this plugin in different environments.
This plugin supports all the utility options with the addition of a callback to retrieve the rename map.
callback can be provided which will be provided with an object to show what
variables were renamed as.
You can utilize this for logging or other tracking purposes.
const postcss = ;const shortCssVars = ;const fs = ;
See the utility for how the default formatting works. If you wish to use a different pattern, simply provide a different formatter function via options.
const postcss = ;const shortCssVars = ;const fnv1a = ;
name provided to the formatter is the variable name WITHOUT the '--'
prefix. The return value should also be name-only. So
If you need to avoid hashing certain variable names, you can ignore them with this option by either RegExp, function, or string (which will be turned into RegExp). This can be useful if you are referencing CSS Variables in an app, yet you do not have control over some of the declarations.
const postcss = ;const shortCssVars = ;
In another scenario, if you have several short variable names (for example
--blue) you can use a function to ignore names by length.
name provided to ignore is the variable name WITHOUT the '--' prefix. So
blue rather than