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

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  const isProd = mode === 'production'

  return {
    plugins: [vue()],
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
        },
      },
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },
    define: {
      VE_ENV: {
        MODE: JSON.stringify(isProd ? 'production' : 'development'),
        SERVER: JSON.stringify(env.VITE_SERVER ?? ''),
        PYSERVER: JSON.stringify(env.VITE_PYSERVER ?? ''),
        MOCK: JSON.stringify(env.VITE_MOCK ?? 'False'),
      },
    },
  }
})
