import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'

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

  return {
    plugins: [vue()],
    optimizeDeps: {
      include: ['buffer'],
    },
    // 默认 assetsDir 为 `assets`，与 Vue 路由 `/assets`（我的资产）在 Nginx 上冲突——会优先匹配磁盘目录导致 403。
    build: {
      assetsDir: 'static',
    },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
        buffer: 'buffer',
      }
    },
    server: {
	  host: '0.0.0.0',
      port: 5173,
      proxy: {
        '/api': {
          target: env.VITE_API_PROXY_TARGET,
          changeOrigin: true,
          secure: false,
        },
      },
    },
  }
})
