import { defineConfig } from 'vite';
import { resolve } from 'path';

export default defineConfig(({ mode }) => {
  const isFirefox = mode === 'firefox';
  const targetDir = isFirefox ? 'dist/firefox' : 'dist/chrome';

  return {
    root: '.',
    build: {
      outDir: targetDir,
      emptyOutDir: true,
      rollupOptions: {
        input: {
          background: resolve(__dirname, 'src/background/index.ts'),
          content: resolve(__dirname, 'src/content/index.ts'),
          popup: resolve(__dirname, 'src/popup/popup.ts'),
          options: resolve(__dirname, 'src/options/options.ts'),
        },
        output: {
          entryFileNames: '[name].js',
        },
      },
      copyPublicDir: true,
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
      },
    },
  };
});
