Skip to content

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Sep 15, 2021

Currently in the new JIT mode, we can't really use a RegExp for safelisting, because we don't have anything to match against. In AOT mode we generated everything, then when we apply the purge step, we could remove everything except of safelisted values.

This PR provides a way to apply safelisting using RegExp as well, but with a slightly different syntax:

  let config = {
    content: [{ raw: html`<div class="uppercase"></div>` }],
    safelist: [
      {
        pattern: /bg-(red)-(100|200)/,
        variants: ['hover', 'focus'],
      },
    ],
  }

Sadly we can't generate all possible combinations and then test each option against the RegExp... why not? Well...
We have 100 variants (which you can combine) and we have about 6575 utilities by default.
Instead, we generate the 6575 base utilities. These don't have any variants, e.g.: text-gray-200.
We then test the RegExp against these values. If they match, we generate the combinations using the variants you provide in the list.

@RobinMalfait RobinMalfait changed the title Pattern safelisting Pattern safelisting & completions Sep 15, 2021
@RobinMalfait RobinMalfait force-pushed the pattern-safelisting branch 2 times, most recently from b55838e to 544fb25 Compare September 16, 2021 09:28
We want to separate the logic of the formatting the class and of turning
it into a class with a `.` and escaped values.
@RobinMalfait RobinMalfait changed the title Pattern safelisting & completions Pattern safelisting Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant