import vue from "@vitejs/plugin-vue";
import { viteMockServe } from "vite-plugin-mock";

import createAutoImport from "./auto-import";
import createSvgIcon from "./svg-icon";
import createCompression from "./compression";
import createSetupExtend from "./setup-extend";

export default function createVitePlugins(
    viteEnv,
    isBuild = false,
    command = "serve"
) {
    const vitePlugins = [vue()];

    // 开发环境启用mock，需要在其他插件之前注册，确保优先处理请求
    if (!isBuild) {
        vitePlugins.push(
            viteMockServe({
                mockPath: "mock",
                enable: command === "serve", // 仅在开发服务器启动时启用
                supportTs: false,
                watchFiles: true, // 监听文件变化
                logger: true, // 显示请求日志，方便调试
            })
        );
    }

    vitePlugins.push(createAutoImport());
    vitePlugins.push(createSetupExtend());
    vitePlugins.push(createSvgIcon(isBuild));
    isBuild && vitePlugins.push(...createCompression(viteEnv));

    return vitePlugins;
}
