Created
December 2, 2022 18:51
-
-
Save bjankord/33a58fdff82c12c55756f54bf3dfbe8f to your computer and use it in GitHub Desktop.
POSTCSS Find background CSS declarations that use /p/assets/images/1x1.png
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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