Want to stay in contact?

Receive the latest articles straight to your inbox.

We care about privacy and will never spam you. Read our Privacy Policy.

Finding the Right Purgecss Extractor

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
      };
    }
  }
Back Home

Want to stay in contact?

Receive the latest articles straight to your inbox.

We care about privacy and will never spam you. Read our Privacy Policy.

Logo

Building websites and making things.

© 2020 Drew Town. All rights reserved.