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

export default defineConfig({
  main: {
    build: {
      outDir: 'dist/main',
      lib: {
        entry: resolve(__dirname, 'main/index.ts'),
        formats: ['cjs'],
      },
      rollupOptions: {
        external: [
          'bufferutil',
          'utf-8-validate',
          'playwright',
          'playwright-core',
        ],
        output: {
          entryFileNames: 'main.cjs',
        },
      },
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, '../../'),
        'packages': resolve(__dirname, '../../packages'),
        'core/*': resolve(__dirname, '../../core/*'),
      },
    },
  },
  preload: {
    build: {
      outDir: 'dist/preload',
      lib: {
        entry: resolve(__dirname, 'main/preload.ts'),
        formats: ['cjs'],
      },
      rollupOptions: {
        output: {
          entryFileNames: 'preload.js',
        },
      },
    },
  },
  renderer: {
    root: resolve(__dirname, 'renderer'),
    build: {
      outDir: resolve(__dirname, 'dist/renderer'),
      rollupOptions: {
        input: resolve(__dirname, 'renderer/index.html'),
      },
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, '../../'),
      },
    },
    plugins: [react()],
  },
});