import type { Plugin } from 'vite'

export default function processHtml(title: string, script: string = ''): Plugin {
  return {
    name: 'vite-plugin-html-process',
    transformIndexHtml(html) {
      return html.replace(
        /<title>(.*?)<\/title>/,
        `<title>${title}</title>`,
      ).replace(
        /<script><\/script>/,
        script,
      )
    },
  }
}
