import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import UniUnoCSS from 'uni-unocss';
export default async () => {
    const UnoCss = await import('unocss/vite').then((i) => i.default);
    return defineConfig({
        define: {
            'process.env': process.env, // 配置变量在业务代码内生效
        },
        plugins: [
            AutoImport({
                imports: [
                    // 预设
                    'vue',
                    'uni-app',
                    'pinia',
                ],
                dts: true,
            }),
            uni(),
            UniUnoCSS(), // 自动处理平台差异
            visualizer(),
        ],
        css: {
            preprocessorOptions: {
                scss: {
                    // 取消sass废弃API的报警
                    silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],
                },
            },
        },
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src'),
            },
        },
        server: {
            proxy: {
                '/subpackage': {
                    target: 'https://yunnan.yujin.yunyaozhuisu.com',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/subpackage/, '/subpackage'),
                },
                '/pyapi': {
                    target: 'https://yunnan.yujin.yunyaozhuisu.com',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/pyapi/, '/pyapi'),
                },
            },
            // 启动端口
            port: 9090,
            // HMR 配置
            hmr: {
                overlay: true, // 显示错误覆盖层
                clientPort: 9090, // 客户端端口
            },
            watch: {
                // 增加文件监视限制
                usePolling: false,
                interval: 100,
            },
        },
    });
};
