import react from '@vitejs/plugin-react';
import path from 'path';

/**
 * Returns a base Vite config for apps that consume the shared package.
 * Apps can spread this into their own defineConfig and override as needed.
 */
export function createSharedConfig({ root, envDir, base = '/', outDir = 'dist' } = {}) {
  return {
    plugins: [react()],
    base,
    envDir,
    resolve: {
      dedupe: ['react', 'react-dom'],
      alias: {
        '@shared': path.resolve(root || process.cwd(), 'node_modules/@discord-clone/shared/src'),
      },
    },
    build: {
      outDir,
      chunkSizeWarningLimit: 1000,
    },
  };
}
