Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List unused custom properties
// list unused custom properties
// $ node list-unused-custom-properties.js <FILENAME>
const fs = require("fs");
const postcss = require("postcss");
const css = postcss.parse(fs.readFileSync(process.argv[2], "utf8"));
const customProperties = {};
css.walkDecls(decl => {
if (decl.prop.startsWith("--")) {
customProperties[decl.prop] = 0;
}
const variables = decl.value.match(/\bvar\(.*?\)/g);
if (!variables) {
return;
}
variables.forEach(variable => {
const customProperty = variable.replace(/var\((.*?)\)/, "$1");
delete customProperties[customProperty];
});
});
console.log(customProperties);
@hail2u

This comment has been minimized.

Copy link
Owner Author

@hail2u hail2u commented Aug 29, 2019

This works against a concatenated CSS file only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment