Remove or report on unused variable definitions
yarn add -D postcss-dropunusedvars
Via the command line:
postcss -u postcss-dropunusedvars -o dist/index.css src/index.css
In the postcss config:
require("postcss-dropunusedvars")({ fix: true });
fix
Type: boolean
Default: false
Remove unused variables from the output or, if false, report on them to the console.
Assuming you have some variables defined and rule(s) that use them:
:root {
--prefix-component-background-color: blue;
--prefix-component-width: 10px;
--prefix-component-height: 10px;
--prefix-component-size: 10px;
}
.component {
background-color: var(--prefix-component-background-color);
width: var(--prefix-component-width);
height: var(--prefix-component-height);
}
The variables that are not used in any rule will be removed from the output:
:root {
--prefix-component-background-color: blue;
--prefix-component-width: 10px;
--prefix-component-height: 10px;
}
.component {
background-color: var(--prefix-component-background-color);
width: var(--prefix-component-width);
height: var(--prefix-component-height);
}
var()
or var(calc(),)
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Apache 2.0 © Cassondra Roberts