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:
parent
3569d49f7e
commit
8518fee9ea
8 changed files with 188 additions and 2 deletions
20
src/cli.js
20
src/cli.js
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue