import { defineConfig } from 'vite';
import svgr from 'vite-plugin-svgr';
import react from '@vitejs/plugin-react';
import noBundlePlugin from 'vite-plugin-no-bundle';
import fg from 'fast-glob';
import dts from 'vite-plugin-dts';

export default defineConfig({
  plugins: [
    react({ jsxRuntime: 'automatic' }),
    svgr({
      include: ['**/*.svg', '**/*.svg?react'],
    }),
    dts({
      entryRoot: 'src',
      exclude: ['**/*.stories.*', '**/*.test.*', '**/demo/**'],
    }),
    noBundlePlugin({
      root: 'src',
      copy: ['**/*.png', '**/*.gif', '**/*.jpg', '**/*.jpeg', '**/*.d.ts', '**/*.css'],
    }),
  ],
  build: {
    lib: {
      entry: fg.sync('src/**/*.{tsx,ts,jsx,js}', {
        ignore: ['**/stories/**', '**/demo/**', '**/*.d.ts', '**/*.stories.*'],
      }),
      formats: ['es'],
      fileName: (format, entryName) => `${entryName}.js`,
    },
    outDir: 'lib',
    emptyOutDir: true,
    rollupOptions: {
      external: ['@sentry/browser'],
    },
  },
});
