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

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        '@api': path.resolve(__dirname, 'src/api'),
        '@assets': path.resolve(__dirname, 'src/assets'),
        '@comp': path.resolve(__dirname, 'src/components'),
        '@views': path.resolve(__dirname, 'src/views'),
        '@utils': path.resolve(__dirname, 'src/utils')
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          additionalData: `@import "@/styles/variable.less";`,
          javascriptEnabled: true
        }
      }
    },
    server: {
      port: 7999,
      open: true,
      proxy: {
        '/dgapi': {
          target: env.VITE_APP_BASE_API || 'http://192.168.1.7:8999/dgapi',
          changeOrigin: true,
          rewrite: (p: string) => p.replace(/^\/dgapi/, '')
        }
      }
    },
    build: {
      outDir: 'admin',
      assetsDir: 'static'
    }
  }
})
