You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-109
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,9 @@
12
12
## Features
13
13
14
14
* Remove unneeded CSS with ease
15
-
* Webpack or PostCSS mode
16
-
* Already comes with mighty default settings
15
+
* Sane default settings
17
16
* Built on top of [purgecss](https://github.com/FullHuman/purgecss)
18
-
* Nuxt 2 (and only Nuxt 2) support
17
+
* Nuxt 2 and Nuxt 3 support (Use v1.0.0 for Nuxt2 support for now)
19
18
* Fully tested!
20
19
21
20
## Setup
@@ -26,11 +25,11 @@
26
25
yarn add --dev nuxt-purgecss # or npm install --save-dev nuxt-purgecss
27
26
```
28
27
29
-
2. Add `nuxt-purgecss` to the `buildModules` section of `nuxt.config.js`
28
+
2. Add `nuxt-purgecss` to the `modules` section of `nuxt.config.{js,ts}`
30
29
31
30
```js
32
31
exportdefault {
33
-
buildModules: [
32
+
modules: [
34
33
// Simple usage
35
34
'nuxt-purgecss',
36
35
@@ -40,159 +39,79 @@ export default {
40
39
}
41
40
```
42
41
43
-
:warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`.
42
+
:warning: If you are using Nuxt **2**, please use version 1 of the module.
44
43
45
44
## Options
46
45
47
46
### Defaults
48
47
49
-
Before diving into the individual attributes, please have a look [at the default settings](https://github.com/Developmint/nuxt-purgecss/blob/master/lib/utils.js) of the module.
48
+
Before diving into the individual attributes, please have a look [at the default settings](https://github.com/Developmint/nuxt-purgecss/blob/main/src/config.ts) of the module.
50
49
51
-
The defaults will scan all your `.vue` or `.js`components in the common Nuxt folders, as well as checking your `nuxt.config.js` for used classes.
50
+
The defaults will scan all your `.vue`, `.js`and `.ts` files in the common Nuxt folders, as well as checking your `nuxt.config.js` (or `.ts`) for used classes.
52
51
Furthermore, typical classes (like these needed for transitions, the nuxt link ones or those set when using scoped styles) are whitelisted already.
53
52
54
53
These settings should be a good foundation for a variety of projects.
55
54
56
-
### Merging defaults
57
-
58
-
You can define every option either as function or as static value (primitives, objects, arrays, ...).
59
-
if you use a function, the default value will be provided as the first argument.
60
-
61
-
If you *don't* use a function to define you properties, the module will try to
62
-
merge them with the default values. This can be handy for `paths`, `whitelist` and so on because
63
-
the defaults are quite sensible. If you don't want to have the defaults include, just use a function.
64
-
65
55
### Properties in-depth
66
56
67
-
#### mode
68
-
69
-
* Type: `String` ('webpack' or 'postcss')
70
-
* Default: `postcss`
71
-
72
-
Defines the mode, PurgeCSS should be used in.
73
-
74
-
* Webpack mode can only be used with `build.extractCSS: true`
75
-
* PostCSS mode can only be used with a `build.postcss`**object** (no array) or default settings
* Don't forget to add paths to pages and components that are not part the common folders (e.g. third party packages)
101
+
* The default generated 500 and 404 pages will be purged by default. Please ensure you have an appropriate error layout
102
+
* Do not use the old `>>>` or `::v-deep` syntax. Instead, go for `:deep`
149
103
150
-
### Use custom extractors
104
+
##Migrating from v1.x
151
105
152
-
Only one extractor can be applied to each file extention.
153
-
If you want to apply a custom extractor to the extensions that the default extractor already covers, you have to override the default extractor. This is only possible with the functional notation.
106
+
:warning: If you use Nuxt 2, you can't update to v2.x (yet?)
154
107
155
-
```js
156
-
//nuxt.config.js
157
-
exportdefault {
158
-
buildModules: [
159
-
'nuxt-purgecss',
160
-
],
161
-
162
-
purgeCSS: {
163
-
extractors: () => [
164
-
{
165
-
extractor(content) {
166
-
returncontent.match(/[A-z0-9-:\\/]+/g)
167
-
},
168
-
extensions: ['html', 'vue', 'js']
169
-
},
170
-
{
171
-
extractor(content) {
172
-
returncontent.match(/[A-z0-9-\\/]+/g)
173
-
},
174
-
extensions: ['vue'] // This will not work, because the above extractor is applied to 'vue' already.
175
-
}
176
-
]
177
-
}
178
-
}
179
-
```
108
+
1. The webpack mode has been removed, as Nuxt 3 supports Vite and webpack. This way, the logic is unified to use the PostCSS plugin of PurgeCSS. There is no `mode` anymore
109
+
2. The config merging logic of v1 has been removed in favor of using [`defu`](https://github.com/unjs/defu). Instead of using functions, write your values as usual and they will be merged.
110
+
3. PurgeCSS has been bumped from v2.x to v5.x - Please check the current [config options](https://purgecss.com/configuration.html#options)
111
+
4. Change the module key has been changed to just `purgecss`.
112
+
5. In addition to `enabled`, all purgecss configurations can be written directly into the `purgecss` object.
113
+
6. Eventually, check out the playground of the module and the [current defaults]([at the default settings](https://github.com/Developmint/nuxt-purgecss/blob/main/src/config.ts))!
180
114
181
-
## Migrating from v0.x
182
-
183
-
1. Review the [**Release Notes**](./CHANGELOG.md) for all changes
184
-
2. Bump to 1.x
185
-
3. Ensure the plugin is running in the right mode
186
-
* If you used the default mode, you have to add `mode: 'webpack'` to your config.
187
-
* If you used the `postcss` mode, you can remove the `mode: 'postcss'` line from your config
188
-
* If you used this module only with the [Nuxt `tailwind` module](https://github.com/nuxt-community/tailwindcss-module), you don't need to do anything
189
-
4. Read about the internal changes of [PurgeCSS 2](https://github.com/fullhuman/purgecss/releases)
190
-
5. Update your extractor and change the syntax from a class to a function (see 4.)
191
-
6. Unused styles from SFCs are now purged. If you don't want that, whitelist them.
192
-
7. The regex for CSS classes changed. This should not be breaking in most cases.
193
-
8. The whitelist now includes nuxt link classes (e.g. `nuxt-link-active`). If you whitelisted these before, you can remove them.
194
-
9. The whitelist now includes move transition classes. If you whitelisted these before, you can remove them.
195
-
10. Test on your staging server (or locally) before deploying!
0 commit comments