fix: inline global css that's not at beginning of line (#141)

This commit is contained in:
Daniel Roe 2022-07-20 15:48:53 +01:00 committed by GitHub
parent eae6c55bae
commit f650a70197

View File

@ -87,7 +87,13 @@ export const RenderPlugin = () => {
return `\${${r.slice(2, -2)}}`.replace(/messages\./g, 'props.') return `\${${r.slice(2, -2)}}`.replace(/messages\./g, 'props.')
}) })
const styleContent = Array.from(html.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/g)).map(block => block[1]).join('\n') const styleContent = Array.from(html.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/g)).map(block => block[1]).join('\n')
const globalStyles = styleContent.match(/^([^.][^{]*\{[^}]*\})*/)?.[0] const globalStyles = styleContent.replace(/(\.[^{]*\{[^}]*\})+.?/g, (r) => {
const lastChar = r[r.length - 1]
if (lastChar && !['}', '.', '@', '*', ':'].includes(lastChar)) {
return ';' + lastChar
}
return lastChar
}).replace(/@media[^{]*\{\}/g, '')
const inlineScripts = Array.from(html.matchAll(/<script>([\s\S]*?)<\/script>/g)) const inlineScripts = Array.from(html.matchAll(/<script>([\s\S]*?)<\/script>/g))
.map(block => block[1]) .map(block => block[1])
.filter(i => !i.includes('const t=document.createElement("link")')) .filter(i => !i.includes('const t=document.createElement("link")'))