Finding the Right Purgecss Extractor
Drew Town
Posted on May 12, 2019
When I was writing the tutorial on Setting up Tailwind with Purgecss I was running into an issue where my Vue.js computed styles were getting purged by Purgecss. I was having a hell of a time and hat tip to @adamwathan, the creator of Tailwind, for pointing me in the right direction.
When considering the "default" extractor for Tailwind /[A-Za-z0-9-_:/]+/
it would absolute make sense that hidden:
would be considered a valid class name. Unfortunately if hidden:
is the only place that our hidden class name appears then the class name that we really want hidden
will no longer be in our CSS file.
Playing around with the RegEx and my Vue files I was able to adjust my RegEx to use the \b
meta character on both the beginning and end of the RegEx.
/\b[A-Za-z0-9-_:/]+\b/g
This has worked perfectly for me as I do not use any special characters to start or end my CSS classes and I do not see any cases where Tailwind does either. So now in my computed properties the RegEx finds only hidden
and not hidden:
.
computed: {
navClasses() {
return {
block: this.navOpen,
hidden: !this.navOpen
};
}
}
Posted on May 12, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.