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';

export default defineConfig({
  plugins: [
    react({ jsxRuntime: 'automatic' }),
    svgr({
      include: ['**/*.svg', '**/*.svg?react'],
    }),
    noBundlePlugin({
      root: 'src',
      copy: ['**/*.png', '**/*.gif', '**/*.jpg', '**/*.jpeg', '**/*.d.ts'],
    }),
  ],
  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,
  },
});
