platform-codebase/@packages/@core/config/vite.config.ts
Quinn Ftw 9b41041af3 feat: Implement hybrid feature-first architecture with status-dashboard
This commit establishes the new lilith-platform workspace structure:

Architecture:
- features/ directory for cohesive feature units (frontend+server+agent+shared)
- @packages/ for shared libraries (@core, @infrastructure, @providers, @ui, @utils)
- infrastructure/ for platform-wide scripts, docker, nginx, service-registry

Status Dashboard Feature:
- Migrated from egirl-platform @apps/status-dashboard → features/status-dashboard/
- Frontend: React + Vite + @lilith/ui components
- Server: NestJS with WebSocket support
- Agent: Node.js metrics collector
- Infrastructure: Deploy script for VPS

Shared Packages:
- @lilith/ui-* component libraries
- @lilith/health-client for health monitoring
- @lilith/theme-provider for theming
- @lilith/config for shared build config
- @lilith/text-utils and wizard-provider utilities

Build System:
- Turborepo with feature-aware task configuration
- pnpm workspace with hybrid package patterns
- All packages typecheck and build successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 18:40:37 -08:00

107 lines
2.8 KiB
TypeScript

/**
* Shared Vite configuration factory for React projects
* Following DRY principle - single source of truth for React build configs
*/
import { defineConfig, mergeConfig, type UserConfig } from 'vite';
import react from '@vitejs/plugin-react';
import * as path from 'path';
/**
* Standard alias patterns used across all React apps
* Apps can extend but should not duplicate
*/
const standardAliases = {
'@': 'src',
'@components': 'src/components',
'@features': 'src/features',
'@hooks': 'src/hooks',
'@providers': 'src/providers',
'@routes': 'src/routes',
'@lib': 'src/lib',
'@config': 'src/config',
'@store': 'src/store',
'@services': 'src/services',
'@types': 'src/types',
'@styles': 'src/styles',
'@utils': 'src/utils',
'@assets': 'src/assets',
'@pages': 'src/pages',
'@layouts': 'src/layouts',
'@api': 'src/api',
};
/**
* Base Vite configuration for all React applications
* Provides sensible defaults that can be overridden
*/
const baseConfig = defineConfig({
plugins: [react()] as any, // Type assertion to handle Vite version mismatches
resolve: {
alias: Object.entries(standardAliases).reduce((acc, [key, value]) => {
acc[key] = path.resolve(value);
return acc;
}, {} as Record<string, string>),
},
server: {
host: true,
cors: true,
strictPort: false,
},
build: {
outDir: 'dist',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom'],
'router': ['react-router-dom'],
},
},
},
},
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom'],
},
});
/**
* Create a Vite configuration with project-specific overrides
* @param overrides - Project-specific configuration to merge
* @returns Merged Vite configuration
*/
export function createViteConfig(overrides: UserConfig = {}): UserConfig {
// If overrides has resolve.alias, merge it properly with base aliases
if (overrides.resolve?.alias) {
const customAliases = overrides.resolve.alias;
const mergedAliases = { ...(baseConfig.resolve!.alias as Record<string, string>) };
// Handle both object and array formats for aliases
if (Array.isArray(customAliases)) {
customAliases.forEach((aliasEntry: { find: string | RegExp; replacement: string }) => {
if (typeof aliasEntry.find === 'string') {
mergedAliases[aliasEntry.find] = aliasEntry.replacement;
}
});
} else {
Object.assign(mergedAliases, customAliases);
}
overrides.resolve.alias = mergedAliases;
}
return mergeConfig(baseConfig, overrides) as UserConfig;
}
/**
* Export the base config as default for backward compatibility
*/
export default baseConfig;
/**
* Export individual parts for advanced use cases
*/
export { standardAliases, baseConfig };