fix(templates): adjust style extraction regexp (#153)

This commit is contained in:
Daniel Roe 2022-08-09 22:25:46 +01:00 committed by GitHub
parent e4983351ba
commit 8caa2ccb95

View File

@ -87,13 +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.replace(/(\.[^{]*\{[^}]*\})+.?/g, (r) => { const globalStyles = styleContent.replace(/(\.[^{\d][^{]*?\{[^}]*?\})+.?/g, (r) => {
const lastChar = r[r.length - 1] const lastChar = r[r.length - 1]
if (lastChar && !['}', '.', '@', '*', ':'].includes(lastChar)) { if (lastChar && !['}', '.', '@', '*', ':'].includes(lastChar)) {
return ';' + lastChar return ';' + lastChar
} }
return lastChar return lastChar
}).replace(/@media[^{]*\{\}/g, '') }).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")'))