Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

Commit

Permalink
fix: Try custom extractor for Tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
floric committed Aug 25, 2020
1 parent 6819afa commit 138c1b3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/template/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const generatePage = async (
const res = await purger.purge({
content: [{ extension: "html", raw: `<html><body>${body}</body></html>` }],
css: [{ raw: css }],
defaultExtractor: (content) => {
// Capture as liberally as possible, including things like `h-(screen-1.5)`
const broadMatches = content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || [];

// Capture classes within other delimiters like .block(class="w-1/2") in Pug
const innerMatches = content.match(/[^<>"'`\s.()]*[^<>"'`\s.():]/g) || [];

return broadMatches.concat(innerMatches);
},
});

const reducedCss = res.map((n) => n.css).reduce((a, b) => `${a}\n${b}`);
Expand Down

0 comments on commit 138c1b3

Please sign in to comment.