implement purge safelist (#4580)

* fix --help output in tests

* add tests to ensure we can use `purge.safelist`

* implement the `purge.safelist` for strings

* proxy `purge.safelist` to `purge.options.safelist`

This allows us to have a similar API in `AOT` and `JIT` mode.

* only proxy `purge.safelist` to `purge.options.safelist` if
`purge.options.safelist` doesn't exists yet.
This commit is contained in:
Robin Malfait 2021-06-09 16:00:09 +02:00 • committed by GitHub
parent 3569d49f7e
commit 8518fee9ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 188 additions and 2 deletions

View file

@ -356,7 +356,25 @@ async function build() {
}
function extractContent(config) {
return Array.isArray(config.purge) ? config.purge : config.purge.content
let content = Array.isArray(config.purge) ? config.purge : config.purge.content
return content.concat(
(config.purge?.safelist ?? []).map((content) => {
if (typeof content === 'string') {
return { raw: content, extension: 'html' }
}
if (content instanceof RegExp) {
throw new Error(
"Values inside 'purge.safelist' can only be of type 'string', found 'regex'."
)
}
throw new Error(
`Values inside 'purge.safelist' can only be of type 'string', found '${typeof content}'.`
)
})
)
}
function extractFileGlobs(config) {