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: [
          '@nut-tree-fork/nut-js',
          '@nut-tree-fork/libnut',
          '@nut-tree-fork/libnut-darwin',
          '@nut-tree-fork/libnut-linux',
          '@nut-tree-fork/libnut-win32',
          '@nut-tree-fork/node-mac-permissions',
          '@nut-tree-fork/default-clipboard-provider',
          '@nut-tree-fork/provider-interfaces',
          '@nut-tree-fork/shared',
          'bufferutil',
          'utf-8-validate',
        ],
        output: {
          entryFileNames: 'main.cjs',
        },
      },
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, '../../'),
      },
    },
  },
  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()],
  },
});