import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';

export default defineConfig({
  plugins: [react()],
  base: './',
  envDir: '../../', // Pick up .env.local from project root (for VITE_CONVEX_URL)
  resolve: {
    dedupe: ['react', 'react-dom'],
    alias: {
      '@discord-clone/shared': path.resolve(__dirname, '../../packages/shared'),
      '@discord-clone/ui': path.resolve(__dirname, '../../packages/ui/src'),
      '@discord-clone/constants': path.resolve(__dirname, '../../packages/constants/src'),
      '@brycord/ui': path.resolve(__dirname, '../../packages/ui/src'),
      '@brycord/constants': path.resolve(__dirname, '../../packages/constants/src'),
      '@brycord/matrix-client': path.resolve(__dirname, '../../packages/shared/src/_shims/matrix-client.ts'),
      '@app/stores': path.resolve(__dirname, '../../packages/shared/src/_shims/stores'),
      '@app/actions': path.resolve(__dirname, '../../packages/shared/src/_shims/actions'),
      '@app/components': path.resolve(__dirname, '../../packages/shared/src/components'),
      '@app/hooks': path.resolve(__dirname, '../../packages/shared/src/_shims/app/hooks'),
      '@app/utils': path.resolve(__dirname, '../../packages/shared/src/_shims/app/utils'),
      '@app/data': path.resolve(__dirname, '../../packages/shared/src/_shims/app/data'),
      '@app': path.resolve(__dirname, '../../packages/shared/src/_shims/app'),
      'mobx-react-lite': path.resolve(__dirname, '../../packages/shared/src/_shims/mobx-react-lite.ts'),
      mobx: path.resolve(__dirname, '../../packages/shared/src/_shims/mobx.ts'),
    },
  },
  css: {
    modules: {
      localsConvention: 'camelCaseOnly',
    },
  },
  build: {
    outDir: 'dist-react',
    chunkSizeWarningLimit: 1000,
  },
});
