/*
 * @Author: donghao donghao@supervision.ltd
 * @Date: 2025-03-06 11:27:03
 * @LastEditors: donghao donghao@supervision.ltd
 * @LastEditTime: 2025-03-07 14:35:23
 * @FilePath: \vite-ai\data-dashboard\vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineConfig, loadEnv } from 'vite'
import { resolve } from "path";
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import AutoImport from "unplugin-auto-import/vite";

/** 路径查找 */
const pathResolve = (dir: string): string => {
  return resolve(__dirname, ".", dir);
};

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')

  return {
    resolve: {
      alias: [
        { find: /^@\//, replacement: resolve(__dirname, "src") + "/" },
        { find: /^~/, replacement: "" },
        { find: /^@build\//, replacement: pathResolve("build") }
      ]
    },
    plugins: [
      vue(),
      viteMockServe({
        mockPath: 'mock',
        localEnabled: env.VITE_MOCK_ENABLED === 'true'
      }),
      AutoImport({
        imports: ["vue"],
        eslintrc: {
          enabled: true
        }
      })
    ],
    server: {
      port: parseInt(env.VITE_PORT) || 5050
    },
    define: {
      'process.env': env
    }
  }
})