import type { theOptions } from './types/index.d'

/**
 * @envPrefix 配置环境变量前缀默认 VITE_
 * @envDir 配置环境变量路径，默认为项目根目录
 * @title 网站标题
 */
const onReturnPlugin = (opthons?: theOptions): any => {
    return {
        envPrefix: opthons?.envPrefix || "VITE_",
        config(config: any, env: any) {
            return {
                envDir: opthons?.envDir || '',
            }
        },
        transformIndexHtml(html: any) {
            if (opthons?.title) {
                return html.replace(
                    /<title>(.*?)<\/title>/,
                    `<title>${opthons.title}</title>`
                )
            }
            return null

        }
    }
}


export default onReturnPlugin;