Skip to content

Commit 942d0b9

Browse files
committed
Add purge information to README
1 parent ba33d77 commit 942d0b9

File tree

1 file changed

+62
-11
lines changed

1 file changed

+62
-11
lines changed

README.md

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ A plugin that provides a set of `prose` classes you can use to add beautiful typ
1414

1515
## Installation
1616

17-
1817
Install the plugin from npm:
1918

2019
```sh
@@ -43,22 +42,31 @@ module.exports = {
4342
### Using a CDN
4443

4544
If you need to pull in these styles via CDN, you can do so using services like UNPKG or jsDeliver:
46-
45+
4746
```html
4847
<!-- From UNPKG -->
49-
<link rel="stylesheet" href="https://unpkg.com/@tailwindcss/typography@0.2.x/dist/typography.min.css">
48+
<link
49+
rel="stylesheet"
50+
href="https://unpkg.com/@tailwindcss/typography@0.2.x/dist/typography.min.css"
51+
/>
5052

5153
<!-- From jsDelivr -->
52-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tailwindcss/typography@0.2.x/dist/typography.min.css">
54+
<link
55+
rel="stylesheet"
56+
href="https://cdn.jsdelivr.net/npm/@tailwindcss/typography@0.2.x/dist/typography.min.css"
57+
/>
5358
```
5459

5560
To use these styles alongside the rest of Tailwind via CDN, we recommend pulling in each layer separately so you can put the styles in the correct order:
5661

5762
```html
58-
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/base.min.css">
59-
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/components.min.css">
60-
<link rel="stylesheet" href="https://unpkg.com/@tailwindcss/typography@0.2.x/dist/typography.min.css">
61-
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/utilities.min.css">
63+
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/base.min.css" />
64+
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/components.min.css" />
65+
<link
66+
rel="stylesheet"
67+
href="https://unpkg.com/@tailwindcss/typography@0.2.x/dist/typography.min.css"
68+
/>
69+
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/utilities.min.css" />
6270
```
6371

6472
## Usage
@@ -127,6 +135,49 @@ None of the sizes are automatically responsive, but responsive variants are prov
127135
</article>
128136
```
129137

138+
## Purging unused styles
139+
140+
Since the typography styles are added to the `components` layer and Tailwind only purges `utilities` by default, you will notice that even with the `purge` option configured in your `tailwind.config.js` file, all of the typography styles still remain in your final CSS.
141+
142+
If you'd like to purge unused typography styles, you'll need to use the `mode: 'all'` option in your `purge` configuration:
143+
144+
```js
145+
// tailwind.config.js
146+
module.exports = {
147+
purge: {
148+
mode: 'all',
149+
content: [
150+
// Paths to your templates here...
151+
],
152+
},
153+
}
154+
```
155+
156+
It's important to note that if you are using markdown for any of your source files (perhaps you're working on a blog or similar), that you need to be careful not to accidentally purge styles you actually need.
157+
158+
Markdown files for example contain no actual `h2`, `blockquote`, `strong`, etc. elements, so PurgeCSS will remove those styles because it doesn't think you need them.
159+
160+
You have two options for solving this:
161+
162+
1. Safelist all of the plain HTML elements you need in your config file:
163+
164+
```js
165+
// tailwind.config.js
166+
module.exports = {
167+
purge: {
168+
mode: 'all',
169+
content: [
170+
// Paths to your templates here...
171+
],
172+
options: {
173+
whitelist: ['h1', 'h2', 'h3', 'p', 'blockquote', 'strong' /* etc. */],
174+
},
175+
},
176+
}
177+
```
178+
179+
2. Use a custom extractor to compile your markdown files _before_ scanning them for tokens. This is more complicated but it is [what we do for the Tailwind blog](https://github.com/tailwindlabs/blog.tailwindcss.com/blob/eb2a0ff80c8e56a79f6514c8dc4253ef84ac5548/tailwind.config.js#L13) for example.
180+
130181
## Customization
131182

132183
> The customization API is currently extremely low-level in order to be as flexible as possible. We will be introducing higher-level configuration options over time as we learn what types of customizations are most common.
@@ -170,9 +221,9 @@ module.exports = {
170221
color: theme('colors.gray.800'),
171222

172223
// ...
173-
}
174-
}
175-
})
224+
},
225+
},
226+
}),
176227
},
177228
plugins: [
178229
require('@tailwindcss/typography'),

0 commit comments

Comments
 (0)