From e26316f8ee4a86c4ea5d63be0008f1a5098e9a02 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 30 Jan 2020 12:06:32 +0100 Subject: [PATCH] feat(purgecss2): change extractor and make it backward compatible --- README.md | 13 +++++++++++++ lib/module.js | 15 +++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a22140c..21d1574 100755 --- a/README.md +++ b/README.md @@ -11,6 +11,19 @@ [📖 **Release Notes**](./CHANGELOG.md) +## Release Note for purgecss 2 +The extractor is now a function that takes the content as an argument. +```js +class Extractor { + static extract(content) {} +} +``` +changes to +```js +function extractor(content) {} +``` + + ## Features * Remove unneeded CSS with ease diff --git a/lib/module.js b/lib/module.js index da20f35..bcc429a 100644 --- a/lib/module.js +++ b/lib/module.js @@ -32,10 +32,8 @@ export default function nuxtPurgeCss(moduleOptions) { whitelistPatternsChildren: [], extractors: [ { - extractor: class { - static extract(content) { - return content.match(/[A-z0-9-:\\/]+/g) || [] - } + extractor(content) { + return content.match(/[A-z0-9-:\\/]+/g) || [] }, extensions: ['html', 'vue', 'js'] } @@ -95,6 +93,15 @@ export default function nuxtPurgeCss(moduleOptions) { return } + if (config.extractors) { + config.extractors.forEach((e) => { + if (e.extractor && e.extractor.extract) { + logger.warn(`extractors need to be defined as function now, transformed class definition to function`) + e.extractor = e.extractor.extract + } + }) + } + const purgeCssPluginsObject = { '@fullhuman/postcss-purgecss': { content: config.paths,