diff --git a/packages/ui-templates/lib/render.ts b/packages/ui-templates/lib/render.ts index 27f0c3bf4a..cc62479a78 100644 --- a/packages/ui-templates/lib/render.ts +++ b/packages/ui-templates/lib/render.ts @@ -27,7 +27,11 @@ export const RenderPlugin = () => { const critters = new Critters({ path: outputDir }) const htmlFiles = await globby(resolve(outputDir, 'templates/**/*.html'), { absolute: true }) - const templateExports = [] + const templateExports: Array<{ + exportName: string + templateName: string + types: string + }> = [] for (const fileName of htmlFiles) { // Infer template name @@ -48,9 +52,13 @@ export const RenderPlugin = () => { html = html.replace(/]*>/g, '') // Inline SVGs - const svgSources = Array.from(html.matchAll(/src="([^"]+)"|url([^)]+)/g)) - .map(m => m[1]) - .filter(src => src?.match(/\.svg$/)) + const svgSources: string[] = [] + + for (const [src] of html.matchAll(/src="([^"]+)"|url([^)]+)/g)) { + if (src?.match(/\.svg$/)) { + svgSources.push(src) + } + } for (const src of svgSources) { const svg = readFileSync(join(outputDir, src), 'utf-8') @@ -59,8 +67,13 @@ export const RenderPlugin = () => { } // Inline our scripts - const scriptSources = Array.from(html.matchAll(/]*src="([^"]*)"[^>]*>[\s\S]*?<\/script>/g)) - .filter(([_block, src]) => src?.match(/^\/.*\.js$/)) + const scriptSources: [string, string][] = [] + + for (const [block, src] of html.matchAll(/]*src="([^"]*)"[^>]*>[\s\S]*?<\/script>/g)) { + if (src?.match(/^\/.*\.js$/)) { + scriptSources.push([block, src]) + } + } for (const [scriptBlock, src] of scriptSources) { let contents = readFileSync(join(outputDir, src), 'utf-8') @@ -83,8 +96,10 @@ export const RenderPlugin = () => { const chunks = html.split(/\{{2,3}[^{}]+\}{2,3}/g).map(chunk => JSON.stringify(chunk)) const hasMessages = chunks.length > 1 let templateString = chunks.shift() - for (const expression of html.matchAll(/\{{2,3}([^{}]+)\}{2,3}/g)) { - templateString += ` + (${expression[1].trim()}) + ${chunks.shift()}` + for (const [_, expression] of html.matchAll(/\{{2,3}([^{}]+)\}{2,3}/g)) { + if (expression) { + templateString += ` + (${expression.trim()}) + ${chunks.shift()}` + } } if (chunks.length > 0) { templateString += ' + ' + chunks.join(' + ') @@ -110,7 +125,7 @@ export const RenderPlugin = () => { .replace(/>\{\{\{\s*(\w+)\s*\}\}\}<\/[\w-]*>/g, ' v-html="$1" />') // We are not matching