diff --git a/packages/nuxt/src/pages/route-rules.ts b/packages/nuxt/src/pages/route-rules.ts index fef075e03e..24acf217b1 100644 --- a/packages/nuxt/src/pages/route-rules.ts +++ b/packages/nuxt/src/pages/route-rules.ts @@ -18,11 +18,12 @@ export async function extractRouteRules (code: string): Promise]*>([\s\S]*?)<\/script[^>]*>/i +const SFC_SCRIPT_RE = /[^>]*)>(?[\s\S]*?)<\/script[^>]*>/i export function extractScriptContent (html: string) { - const match = html.match(SFC_SCRIPT_RE) + const groups = html.match(SFC_SCRIPT_RE)?.groups || {} - if (match && match[1]) { - return match[1].trim() + if (groups.content) { + return { + loader: groups.attrs.includes('tsx') ? 'tsx' : 'ts', + code: groups.content.trim(), + } as const } return null @@ -185,12 +188,12 @@ async function getRouteMeta (contents: string, absolutePath: string): Promise + + + +