question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for within brackets [] styles

See original GitHub issue

I have the following class being deleted by purgecss: [class*=btn-][aria-pressed=false] So I added REGEX to try to avoid to delete the style class from the stylesheet by adding it to the whitelistPatterns

  .pipe(postcss([
    purgecss({
      content: [
        './views/**/*.twig',
        './views/**/*.vue'
      ],
      whitelistPatterns: [
        /** Patterns */
        /o-[\S]*/g, // matches object patterns
        /c-[\S]*/g, // matches component patterns
        /** Button Patterns */
        /btn[\S]*/g, // matches "btn{{ token }}"
        /\[(class..btn-)\]\[(aria-[a-z]{7}=([a-z]{5}|[a-z]{4}))\]/g,
      /**
       * Tailwindcss Extractor
       * @source https://tailwindcss.com/docs/controlling-file-size#setting-up-purge-css-manually
       */
      defaultExtractor: content => {
        // Capture as liberally as possible, including things like `h-(screen-1.5)`
        return content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || [];
      }
    }),

The REGEX pattern when tested on an online tool seems to work as shown in the image below: Screen Shot 2020-09-11 at 12 36 56 PM

So in theory the regex /\[(class..btn-)\]\[(aria-[a-z]{7}=([a-z]{5}|[a-z]{4}))\]/ should be preventing the class [class*=btn-][aria-pressed=false] to be deleted since is added to the whitelistPatterns. However, the class is still beind removed from the stylesheet.

I wonder if this is due to the [] square brackets being used, is there any guidance on how to avoid having that class being removed?

this is how is suppose to behave: Image-1

but it is being shown like this: Screen Shot 2020-09-11 at 5 34 37 PM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jayvanhucommented, Sep 21, 2020

Can you reopen the issue please? Even though you found a work around, the bug still exists, and I think it’s important that the repo owners see that this is still an issue for people who do want to whitelist their attribute selectors.

0reactions
Fflorielcommented, Oct 26, 2020

The original issue might be related to the selectors being missing in the content.

    <div class="btn-hello" aria-pressed="false">
        <h1>Hello</h1>
    </div>
[class*=btn-][aria-pressed=false] {
  width: 500px;
}

works as expected.

If anyone has an issue with attributes, could you go to https://github.com/FullHuman/purgecss/issues/303 and link to a repo that reproduces the issue, it will help understand what is the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Citation styles with numbers in brackets [5 examples] - BibGuru
We compiled a list of the main citation styles with numbers in brackets to help you get started with your paper. Each style...
Read more >
Brackets vs. Parentheses - APA (6/e) Style Guide
A guide to help users create citations using APA (American Psychological ... Use brackets inside parentheses to create a double enclosure in the...
Read more >
How to Use Brackets in Academic Writing: Some Common Rules
Different types of brackets are used in academic writing based on discipline and style guide. This article provides common rules in APA, MLA, ......
Read more >
Brackets and parentheses | Style Manual
Write brackets in the same type as the surrounding text ... Brackets should be in the same type (roman, italics, bold) as the...
Read more >
Brackets, Braces, and Parentheses - Where to Use Them
You will come across four types of brackets: Curved Brackets or Parentheses, Square brackets or Brackets, Angle Brackets, and Curly Brackets. As ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found