import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

export default defineConfig(({ mode }) => {
  // 加载对应的环境变量
  const env = loadEnv(mode, process.cwd(), 'VITE_')
  const platform = env.VITE_PLATFORM || 'web'
  
  return {
    plugins: [vue()],
    base: './',
    build: {
      outDir: `dist/${platform}`,
      emptyOutDir: true,
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
      },
    },
    define: {
      __PLATFORM__: JSON.stringify(platform),
    },
  }
})
