-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Purge plugin overhaul (#27)
- Loading branch information
1 parent
d66aea0
commit 0f75105
Showing
18 changed files
with
1,097 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-tailwind-purgecss': minor | ||
--- | ||
|
||
breaking: Updated the default purging strategy to only target Tailwind specific classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-tailwind-purgecss': minor | ||
--- | ||
|
||
feat: Bundle size differences are now printed during build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-tailwind-purgecss': minor | ||
--- | ||
|
||
feat: Added `legacy` mode that brings back the old plugin behavior |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-tailwind-purgecss': minor | ||
--- | ||
|
||
breaking: Updated plugin option types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-tailwind-purgecss': minor | ||
--- | ||
|
||
breaking: Added `tailwindcss` (v3.3.0 or higher) as a peer-dependency |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# vite-plugin-tailwind-purgecss | ||
|
||
## Legacy Mode | ||
|
||
In previous versions (`v0.2.1` and below), `vite-plugin-tailwind-purgecss` would purge _all_ unused selectors. This proved to be problematic and was beyond the scope of the project. For backwards compatibility, this feature can be brought back by enabling _legacy mode_. | ||
|
||
## Usage | ||
|
||
Legacy mode can be enabled through the following plugin config option: | ||
|
||
```ts | ||
// vite.config.ts | ||
import { purgeCss } from 'vite-plugin-tailwind-purgecss'; | ||
|
||
const config: UserConfig = { | ||
plugins: [purgeCss({ legacy: true })], | ||
}; | ||
``` | ||
|
||
### Safelisting | ||
|
||
If selectors that shouldn't be purged are being removed, simply add them to the `safelist`. | ||
|
||
```ts | ||
// vite.config.ts | ||
import { purgeCss } from 'vite-plugin-tailwind-purgecss'; | ||
|
||
const config: UserConfig = { | ||
plugins: [ | ||
sveltekit(), | ||
purgeCss({ | ||
safelist: { | ||
// any selectors that begin with "hljs-" will not be purged | ||
greedy: [/^hljs-/], | ||
}, | ||
legacy: true, | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
Alternatively, if you'd like to safelist selectors directly in your stylesheets, you can do so by adding special comments: | ||
|
||
```css | ||
/*! purgecss start ignore */ | ||
|
||
h1 { | ||
color: red; | ||
} | ||
|
||
h2 { | ||
color: blue; | ||
} | ||
|
||
/*! purgecss end ignore */ | ||
``` | ||
|
||
You can also safelist selectors directly in the declaration block as well: | ||
|
||
```css | ||
h3 { | ||
/*! purgecss ignore current */ | ||
color: pink; | ||
} | ||
``` | ||
|
||
For further configuration, you can learn more [here](https://purgecss.com/configuration.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.