Skip to content

Commit 923e255

Browse files
authored
chore: upgrade to purgecss 2.x (#74)
1 parent 8463a60 commit 923e255

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111
1212
[📖 **Release Notes**](./CHANGELOG.md)
1313

14+
## Release Note for purgecss 2
15+
The extractor is now a function that takes the content as an argument.
16+
```js
17+
class Extractor {
18+
static extract(content) {}
19+
}
20+
```
21+
changes to
22+
```js
23+
function extractor(content) {}
24+
```
25+
26+
1427
## Features
1528

1629
* Remove unneeded CSS with ease
@@ -57,10 +70,8 @@ Before diving into the individual attributes, here are the default settings of t
5770
whitelist: ['body', 'html', 'nuxt-progress'],
5871
extractors: [
5972
{
60-
extractor: class {
61-
static extract(content) {
62-
return content.match(/[A-z0-9-:\\/]+/g)
63-
}
73+
extractor(content) {
74+
return content.match(/[A-z0-9-:\\/]+/g)
6475
},
6576
extensions: ['html', 'vue', 'js']
6677
}
@@ -185,18 +196,14 @@ export default {
185196
purgeCSS: {
186197
extractors: () => [
187198
{
188-
extractor: class {
189-
static extract(content) {
190-
return content.match(/[A-z0-9-:\\/]+/g)
191-
}
199+
extractor: (content) {
200+
return content.match(/[A-z0-9-:\\/]+/g)
192201
},
193202
extensions: ['html', 'vue', 'js']
194203
},
195204
{
196-
extractor: class {
197-
static extract(content) {
198-
return content.match(/[A-z0-9-\\/]+/g)
199-
}
205+
extractor(content) {
206+
return content.match(/[A-z0-9-\\/]+/g)
200207
},
201208
extensions: ['vue'] // This will not work, because the above extractor is applied to 'vue' already.
202209
}

lib/module.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ export default function nuxtPurgeCss(moduleOptions) {
3232
whitelistPatternsChildren: [],
3333
extractors: [
3434
{
35-
extractor: class {
36-
static extract(content) {
37-
return content.match(/[A-z0-9-:\\/]+/g) || []
38-
}
35+
extractor(content) {
36+
return content.match(/[A-z0-9-:\\/]+/g) || []
3937
},
4038
extensions: ['html', 'vue', 'js']
4139
}
@@ -95,6 +93,15 @@ export default function nuxtPurgeCss(moduleOptions) {
9593
return
9694
}
9795

96+
if (config.extractors) {
97+
config.extractors.forEach((e) => {
98+
if (e.extractor && e.extractor.extract) {
99+
logger.warn(`extractors need to be defined as function now, transformed class definition to function`)
100+
e.extractor = e.extractor.extract
101+
}
102+
})
103+
}
104+
98105
const purgeCssPluginsObject = {
99106
'@fullhuman/postcss-purgecss': {
100107
content: config.paths,

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
"forceExit": true
5555
},
5656
"dependencies": {
57-
"@fullhuman/postcss-purgecss": "^1.1.0",
57+
"@fullhuman/postcss-purgecss": "^2.0.5",
5858
"consola": "^1.4.5",
5959
"glob-all": "^3.1.0",
60-
"purgecss": "^1.1.0",
61-
"purgecss-webpack-plugin": "^1.4.0"
60+
"purgecss": "^2.0.5",
61+
"purgecss-webpack-plugin": "^2.0.5"
6262
},
6363
"devDependencies": {
6464
"@commitlint/cli": "^7.5.2",

0 commit comments

Comments
 (0)