From 138c1b359d9f3f1e99891967c649a369e68fce5c Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Tue, 25 Aug 2020 18:56:29 +0200 Subject: [PATCH] fix: Try custom extractor for Tailwind --- src/template/page.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/template/page.tsx b/src/template/page.tsx index 393e98c..85f4aaa 100644 --- a/src/template/page.tsx +++ b/src/template/page.tsx @@ -33,6 +33,15 @@ export const generatePage = async ( const res = await purger.purge({ content: [{ extension: "html", raw: `${body}` }], 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}`);