import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [TanStackRouterVite(), react(), visualizer({ emitFile: true, open: true, filename: 'stats.html' })],
  define: {
    __APP_VERSION__: JSON.stringify(process.env.npm_package_version),
  },
  build: {
    outDir: '../dist',
    emptyOutDir: true,
    // sourcemap: true,
    rollupOptions: {
      output: {
        manualChunks: {
          react: ['react', 'react-dom'],
          mui: ['@emotion/react', '@emotion/styled', '@fontsource/roboto', '@mui/icons-material', '@mui/material'],
          tanstack: [
            '@tanstack/react-form',
            '@tanstack/react-query',
            '@tanstack/react-query',
            '@tanstack/react-query-devtools',
            '@tanstack/router-devtools',
          ],
          i18n: ['i18next', 'i18next-browser-languagedetector', 'i18next-http-backend', 'react-i18next'],
          zustand: ['zustand'],
        },
      },
    },
  },
  base: '/phpCourse/exam/dist',
});
