import { defineConfig } from 'vite'; import path from 'path'; import fs from 'fs'; import tailwindcss from '@tailwindcss/vite'; import react from '@vitejs/plugin-react'; // ── Monorepo dev aliases (auto-detected) ──────────────────────────────────── // When this vite.config lives inside the xertica-ui monorepo (i.e. the // `components/` directory exists one level up), we alias every `xertica-ui/*` // subpath directly to the TypeScript source so Vite HMR picks up changes // without a full `npm run build` in the library root. // // When this file is copied to a project scaffolded by the CLI, `../components` // does NOT exist and the aliases are simply skipped — the project resolves // `xertica-ui` from node_modules as normal. // ──────────────────────────────────────────────────────────────────────────── const LIB_ROOT = path.resolve(__dirname, '..'); const isMonorepo = fs.existsSync(path.join(LIB_ROOT, 'components', 'index.ts')); const libAliases = isMonorepo ? [ { find: 'xertica-ui/ui', replacement: path.join(LIB_ROOT, 'components/ui/index.ts') }, { find: 'xertica-ui/blocks', replacement: path.join(LIB_ROOT, 'components/blocks/index.ts') }, { find: 'xertica-ui/assistant', replacement: path.join(LIB_ROOT, 'components/assistant/index.ts'), }, { find: 'xertica-ui/layout', replacement: path.join(LIB_ROOT, 'components/layout/index.ts') }, { find: 'xertica-ui/brand', replacement: path.join(LIB_ROOT, 'components/brand/index.ts') }, { find: 'xertica-ui/media', replacement: path.join(LIB_ROOT, 'components/media/index.ts') }, { find: 'xertica-ui/hooks', replacement: path.join(LIB_ROOT, 'components/hooks/index.ts') }, { find: 'xertica-ui/pages', replacement: path.join(LIB_ROOT, 'components/pages/index.ts') }, // Bare `xertica-ui` must come AFTER subpaths (most-specific first). { find: 'xertica-ui', replacement: path.join(LIB_ROOT, 'components/index.ts') }, ] : []; export default defineConfig({ plugins: [ // The React and Tailwind plugins are both required for Make, even if // Tailwind is not being actively used — do not remove them. react(), tailwindcss(), ], resolve: { alias: [ ...libAliases, // Alias @ to the src directory { find: '@', replacement: path.resolve(__dirname, './src') }, ], }, // File types to support raw imports. Never add .css, .tsx, or .ts files to this. assetsInclude: ['**/*.svg', '**/*.csv'], });