Skip to content

Instantly share code, notes, and snippets.

@bjankord
Created December 2, 2022 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjankord/33a58fdff82c12c55756f54bf3dfbe8f to your computer and use it in GitHub Desktop.
Save bjankord/33a58fdff82c12c55756f54bf3dfbe8f to your computer and use it in GitHub Desktop.
POSTCSS Find background CSS declarations that use /p/assets/images/1x1.png
const uniqueValue = [
"/p/assets/images/1x1.png"
];
const plugin = () => ({
postcssPlugin: 'postcss-reverse-props',
Once(root) {
// Transform CSS AST here
root.walkRules(rule => {
// Transform each rule here
rule.walkDecls(decl => {
if (decl.prop === 'background') {
if (uniqueValue.some(value => decl.value.includes(value))) {
// Transform each property declaration here
decl.prop = `/* This is used */ ${decl.prop}`;
}
}
});
});
}
});
plugin.postcss = true;
export default plugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment