Unverified Commit 00504326 authored by Taylor Bryant's avatar Taylor Bryant Committed by GitHub

Update with-tailwindcss to use Tailwind CSS v1.4.0's new built-in purge option (#12327)

parent 88fd9a0d
...@@ -43,13 +43,8 @@ Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&ut ...@@ -43,13 +43,8 @@ Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&ut
## Notes ## Notes
This setup is a basic starting point for using [Tailwind CSS](https://tailwindcss.com) with Next.js. This example also includes the following [PostCSS](https://github.com/postcss/postcss) plugins: This example is a basic starting point for using [Tailwind CSS](https://tailwindcss.com) with Next.js. It includes the following [PostCSS](https://github.com/postcss/postcss) plugins:
- [postcss-preset-env](https://preset-env.cssdb.org/) - Adds stage 2+ features and autoprefixes - [postcss-preset-env](https://preset-env.cssdb.org/) - Adds stage 2+ features and autoprefixes
- [purgecss](https://github.com/FullHuman/purgecss) - Removes unused CSS
## Limitations To control the generated stylesheet's filesize, this example uses Tailwind CSS' [`purge` option](https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css) to remove unused CSS.
### Dynamically generated class strings will be purged
Purgecss takes a very straightforward approach to removing unused CSS. It simply searches an entire file for a string that matches a regular expression. As a result, class strings that are dynamically created in a template using string concatenation will be considered unused and removed from your stylesheet. Tailwind CSS addresses this problem in more detail in [their documentation](https://tailwindcss.com/docs/controlling-file-size#writing-purgeable-html).
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
"react-dom": "^16.12.0" "react-dom": "^16.12.0"
}, },
"devDependencies": { "devDependencies": {
"@fullhuman/postcss-purgecss": "^1.3.0",
"postcss-preset-env": "^6.7.0", "postcss-preset-env": "^6.7.0",
"tailwindcss": "^1.1.4" "tailwindcss": "^1.4.0"
} }
} }
module.exports = { module.exports = {
plugins: [ plugins: ['tailwindcss', 'postcss-preset-env'],
'tailwindcss',
...(process.env.NODE_ENV === 'production'
? [
[
'@fullhuman/postcss-purgecss',
{
content: [
'./pages/**/*.{js,jsx,ts,tsx}',
'./components/**/*.{js,jsx,ts,tsx}',
],
defaultExtractor: content =>
content.match(/[\w-/:]+(?<!:)/g) || [],
},
],
]
: []),
'postcss-preset-env',
],
} }
@import './button.css'; @import './button.css';
/* purgecss start ignore */
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
/* purgecss end ignore */
@tailwind utilities; @tailwind utilities;
.hero { .hero {
......
module.exports = {
purge: ['./components/**/*.js', './pages/**/*.js'],
theme: {
extend: {},
},
variants: {},
plugins: [],
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment