import { defineConfig } from 'tsup';

export default defineConfig([
  {
    entry: { 'core/index': 'src/core/index.ts' },
    format: ['esm', 'cjs'],
    dts: true,
    clean: true,
    target: 'es2020',
    sourcemap: true,
  },
  {
    entry: { 'react/index': 'src/react/index.ts' },
    format: ['esm', 'cjs'],
    dts: true,
    external: ['react'],
    target: 'es2020',
    sourcemap: true,
  },
  {
    entry: { 'web-component/index': 'src/web-component/index.ts' },
    format: ['esm', 'cjs'],
    dts: true,
    target: 'es2020',
    sourcemap: true,
    // React + React DOM are bundled inline (vanilla-JS hosts don't have them).
    // `noExternal` overrides tsup's default behavior of auto-externalizing
    // packages declared in `peerDependencies` — without this the ESM bundle
    // emits a bare `import "react"` that browsers cannot resolve.
    // Minify + production-flag the React build so we ship ~180 KB instead of ~1.6 MB.
    noExternal: ['react', 'react-dom', 'react-dom/client'],
    minify: true,
    define: {
      'process.env.NODE_ENV': '"production"',
    },
  },
]);
