import {
  defineConfig,
  defineViteConfig,
  externalizeDepsPlugin,
} from 'electron-vite';
import { mergeConfig } from 'vite';
import { resolve } from 'path';
import productionConfig from './config/vite.config.prod';
import developmentConfig from './config/vite.config.dev';

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()],
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'electron/main/index.ts'),
        },
      },
    },
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'electron/preload/index.ts'),
        },
      },
    },
  },
  renderer: defineViteConfig(({ mode }) => {
    const config = mergeConfig(
      {
        root: '.',
        build: {
          rollupOptions: {
            input: {
              index: resolve(__dirname, 'index.html'),
            },
          },
        },
      },
      mode === 'production' ? productionConfig : developmentConfig
    );
    return config;
  }),
});
