import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path, { resolve } from 'path' import dts from 'vite-plugin-dts'; const isWatch = process.argv.includes('--watch'); export default defineConfig({ plugins: [ react(), !isWatch && dts({ skipDiagnostics: true, // Skip TypeScript diagnostics to avoid type conflicts staticImport: true, insertTypesEntry: true, }), ].filter(Boolean), resolve: { alias: { "@components-spotlight/*": path.resolve(__dirname, './src/components/Spotlight'), "@components-avatars/*": path.resolve(__dirname, './src/components/Avatars'), "@components-chips/*": path.resolve(__dirname, './src/components/Chips'), "@components-utils/*": path.resolve(__dirname, './src/components/Utils'), "@components-inputs/*": path.resolve(__dirname, './src/components/Inputs'), "@components-modals/*": path.resolve(__dirname, './src/components/Modals'), '@components': path.resolve(__dirname, './src/components'), '@assets': path.resolve(__dirname, './src/assets'), '@utils': path.resolve(__dirname, './src/utils'), '@types': path.resolve(__dirname, './src/types'), '@hooks': path.resolve(__dirname, './src/hooks'), '@': path.resolve(__dirname, './src'), }, }, build: { lib: { // Multiple entries: the full barrel (`index`) plus a browser-safe, // tree-shaken `cookie-consent` entry. The latter lets webpack consumers // (e.g. the Next.js landing) pull ONLY the cookie-consent UI without // dragging in react-toastify (React-17 `render`), pdf.js, or the server // monitor SDK that the full barrel transitively includes. entry: { index: resolve(__dirname, 'src/index.ts'), 'cookie-consent': resolve(__dirname, 'src/components/CookieConsent/index.ts'), }, formats: ['es'], fileName: (_format, entryName) => `${entryName}.js`, }, rollupOptions: { // Externalize peer dependencies. Match exact name OR sub-path imports // (e.g. 'react/jsx-runtime') — never match by raw prefix, otherwise // 'react' silently externalizes 'react-is', 'react-fast-compare', etc. external: (id) => { const exactNames = [ 'react', 'react-dom', 'react-intl', 'react-router-dom', 'pdfjs-dist', 'pdf-lib', 'osx-temperature-sensor', 'fs', 'path', 'os', ]; if (exactNames.includes(id)) return true; if (exactNames.some((name) => id.startsWith(name + '/'))) return true; // x-date-pickers v6's `exports` map exposes only the bare ROOT and a few // named entries — NOT the DIRECTORY sub-paths `AdapterDateFns` and // `PickersDay` that DatePeriodPicker.component imports directly. Left // externalized, those bare directory imports are unresolvable under Node // ESM (ERR_UNSUPPORTED_DIR_IMPORT — breaks vitest in every consumer that // pulls the theme/date components). Bundle exactly those two sub-paths so // the dist carries no such import (the bare root stays external below). // (Icon sub-paths like `@mui/icons-material/AddRounded` are `.js` FILES // and resolve fine, so they stay externalized.) if (id === '@mui/x-date-pickers/AdapterDateFns') return false; if (id === '@mui/x-date-pickers/PickersDay') return false; // Scoped-package prefixes (these always end with '/') const scopedPrefixes = ['@mui/', '@emotion/', '@abyss-project/', '@tanstack/']; return scopedPrefixes.some((prefix) => id.startsWith(prefix)); }, output: { globals: { 'react': 'React', 'react-dom': 'ReactDOM', 'react-router-dom': 'ReactRouterDOM', '@mui/material': 'MaterialUI', '@abyss-project/main': 'AbyssMain', 'react-intl': 'ReactIntl' } } } }, })