diff --git a/package.json b/package.json index 767c5f07f..a9d2618a4 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "tailwindcss": "^1.9" }, "devDependencies": { + "@fullhuman/postcss-purgecss": "^3.0.0", "@graphql-codegen/cli": "^1.17.10", "@graphql-codegen/schema-ast": "^1.17.8", "@graphql-codegen/typescript": "^1.17.10", diff --git a/postcss.config.js b/postcss.config.js index 9e0f0b2ca..ce561e206 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -15,5 +15,23 @@ module.exports = { }, }, ], + [ + '@fullhuman/postcss-purgecss', + { + content: ['./pages/**/*.{tsx}', './components/**/*.{tsx}'], + + // This is the function used to extract class names from your templates + 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) + }, + }, + ], ], } diff --git a/tailwind.config.js b/tailwind.config.js index e6b14b11e..7a7ec1bcd 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -3,12 +3,6 @@ module.exports = { removeDeprecatedGapUtilities: true, purgeLayersByDefault: true, }, - purge: { - content: [ - './pages/**/*.{js,ts,jsx,tsx}', - './components/**/*.{js,ts,jsx,tsx}', - ], - }, theme: { extend: { maxWidth: { diff --git a/yarn.lock b/yarn.lock index 1040a652f..c7588c83f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1153,6 +1153,14 @@ postcss "7.0.32" purgecss "^2.3.0" +"@fullhuman/postcss-purgecss@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@fullhuman/postcss-purgecss/-/postcss-purgecss-3.0.0.tgz#e39bf7a7d2a2c664ed151b639785b2efcbca33ff" + integrity sha512-cvuOgMwIVlfgWcUMqg5p33NbGUxLwMrKtDKkm3QRfOo4PRVNR6+y/xd9OyXTVZiB1bIpKNJ0ZObYPWD3DRQDtw== + dependencies: + postcss "7.0.32" + purgecss "^3.0.0" + "@graphql-codegen/cli@^1.17.10": version "1.18.0" resolved "https://registry.yarnpkg.com/@graphql-codegen/cli/-/cli-1.18.0.tgz#8bfeba3748bbd314551dae609cc92002985e5385" @@ -3503,6 +3511,11 @@ commander@^5.0.0: resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== +commander@^6.0.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.0.tgz#b990bfb8ac030aedc6d11bc04d1488ffef56db75" + integrity sha512-zP4jEKbe8SHzKJYQmq8Y9gYjtO/POJLgIdKgV7B9qNmABVFVc+ctqSX6iXh4mCpJfRBOabiZ2YKPg8ciDw6C+Q== + common-tags@1.8.0, common-tags@^1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.8.0.tgz#8e3153e542d4a39e9b10554434afaaf98956a937" @@ -7082,6 +7095,16 @@ purgecss@^2.3.0: postcss "7.0.32" postcss-selector-parser "^6.0.2" +purgecss@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/purgecss/-/purgecss-3.0.0.tgz#039c191871bb999894222a00c4c8b179fccdb043" + integrity sha512-t3FGCwyX9XWV3ffvnAXTw6Y3Z9kNlcgm14VImNK66xKi5sdqxSA2I0SFYxtmZbAKuIZVckPdazw5iKL/oY/2TA== + dependencies: + commander "^6.0.0" + glob "^7.0.0" + postcss "7.0.32" + postcss-selector-parser "^6.0.2" + qs@6.7.0: version "6.7.0" resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"