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

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()],
    resolve: {
      alias: {
        '@shared': resolve('src/shared')
      }
    },
    // Hidden source maps: emit .map files so a field crash stack (the logger writes
    // raw stacks, CC8) can be symbolicated offline, without referencing/exposing them
    // in the shipped bundle (L170).
    build: { sourcemap: 'hidden' }
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
    resolve: {
      alias: {
        '@shared': resolve('src/shared')
      }
    },
    // Emit CommonJS (.cjs): sandboxed preload scripts must be CJS, and enabling
    // the sandbox (webPreferences.sandbox) is part of the security hardening.
    build: {
      sourcemap: 'hidden',
      rollupOptions: {
        output: {
          format: 'cjs',
          entryFileNames: 'index.cjs'
        }
      }
    }
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src'),
        '@shared': resolve('src/shared')
      }
    },
    plugins: [react()],
    build: { sourcemap: 'hidden' }
  }
})
