import { UserConfig, ConfigEnv, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import basicSsl from "@vitejs/plugin-basic-ssl";
import path from "path";

export default ({ command, mode }: ConfigEnv): UserConfig => {
    const env = loadEnv(mode, process.cwd());
    console.log(env);
    return {
        plugins: [
            vue(),
            basicSsl(),
            createSvgIconsPlugin({
                // 指定需要缓存的图标文件夹
                iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
                // 指定symbolId格式
                symbolId: "icon-[dir]-[name]",
            }),
        ],
        server: {
            https: true,
            // host: "localhost",
            host: '0.0.0.0',
            port: Number(env.VITE_APP_PORT),
            // open: true,
            proxy: {
                "/api": {
                    target: "https://apitest.coinvisoncex.top",
                    changeOrigin: true,
                },
            },
        },
        resolve: {
            alias: {
                "@": path.resolve("./src"),
            },
        },
    };
};
