import { pathToFileURL } from 'node:url' import { parseURL } from 'ufo' import MagicString from 'magic-string' import { parse, walk, ELEMENT_NODE, Node } from 'ultrahtml' import { createUnplugin } from 'unplugin' import type { Component } from '@nuxt/schema' interface TreeShakeTemplatePluginOptions { sourcemap?: boolean getComponents (): Component[] } const PLACEHOLDER_RE = /^(v-slot|#)(fallback|placeholder)/ export const TreeShakeTemplatePlugin = createUnplugin((options: TreeShakeTemplatePluginOptions) => { const regexpMap = new WeakMap() return { name: 'nuxt:tree-shake-template', enforce: 'pre', transformInclude (id) { const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href)) return pathname.endsWith('.vue') }, async transform (code, id) { const template = code.match(/