129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
import { defineConfig, loadEnv } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'path';
|
|
import { lilithPackageResolver } from './src/lib/vite-plugins/lilith-package-resolver';
|
|
import { bunStoreResolver } from './src/lib/vite-plugins/bun-store-resolver';
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
// Load .env file (use .env.example if .env doesn't exist yet)
|
|
const env = loadEnv(mode, process.cwd(), '');
|
|
|
|
const showcaseRoot = __dirname;
|
|
const rootNodeModules = path.resolve(__dirname, '../../../../node_modules');
|
|
|
|
// Parse configuration from environment
|
|
const vitePort = parseInt(env.VITE_PORT || '5200', 10);
|
|
const backendPort = parseInt(env.BACKEND_PORT || '3015', 10);
|
|
const uiPackagesRoot =
|
|
env.UI_PACKAGES_ROOT ||
|
|
path.resolve(__dirname, '../../../../../../../@packages/@ts/@ui-react/packages');
|
|
|
|
// Parse proxy targets (JSON array of paths)
|
|
let proxyTargets: string[] = [];
|
|
try {
|
|
proxyTargets = JSON.parse(env.PROXY_TARGETS || '[]');
|
|
} catch {
|
|
console.warn('Failed to parse PROXY_TARGETS, using empty array');
|
|
}
|
|
|
|
// Build proxy configuration
|
|
const proxy: Record<string, string> = {};
|
|
for (const target of proxyTargets) {
|
|
proxy[target] = `http://localhost:${backendPort}`;
|
|
}
|
|
|
|
// Build alias configuration
|
|
const aliases: { find: string | RegExp; replacement: string }[] = [];
|
|
|
|
// Feature-specific aliases (if configured)
|
|
if (env.FEATURE_FRONTEND_PATH) {
|
|
aliases.push({
|
|
find: /^@\//,
|
|
replacement: path.resolve(__dirname, env.FEATURE_FRONTEND_PATH) + '/',
|
|
});
|
|
}
|
|
if (env.FEATURE_PACKAGE_IMPORT && env.FEATURE_PACKAGE_PATH) {
|
|
aliases.push({
|
|
find: env.FEATURE_PACKAGE_IMPORT,
|
|
replacement: path.resolve(__dirname, env.FEATURE_PACKAGE_PATH),
|
|
});
|
|
}
|
|
|
|
// File system allowlist for HMR
|
|
const fsAllow = [showcaseRoot, rootNodeModules, uiPackagesRoot];
|
|
if (env.FEATURE_FRONTEND_PATH) {
|
|
fsAllow.push(path.resolve(__dirname, env.FEATURE_FRONTEND_PATH));
|
|
}
|
|
if (env.FEATURE_PACKAGE_PATH) {
|
|
fsAllow.push(path.resolve(__dirname, env.FEATURE_PACKAGE_PATH));
|
|
}
|
|
|
|
return {
|
|
test: {
|
|
environment: 'node',
|
|
include: ['src/**/*.test.ts'],
|
|
exclude: ['e2e/**'],
|
|
},
|
|
plugins: [
|
|
lilithPackageResolver({
|
|
uiPackagesRoot,
|
|
rootNodeModules,
|
|
}),
|
|
bunStoreResolver({
|
|
rootNodeModules,
|
|
versionPins: {
|
|
'framer-motion': 11,
|
|
'motion-dom': 11,
|
|
'motion-utils': 11,
|
|
'react-router-dom': 7,
|
|
'tslib': 2,
|
|
},
|
|
}),
|
|
react(),
|
|
],
|
|
resolve: {
|
|
alias: aliases,
|
|
dedupe: [
|
|
// Dedupe @lilith wrapper packages to prevent multiple instances
|
|
'@lilith/ui-styled-components',
|
|
'@lilith/ui-router',
|
|
'@lilith/ui-motion',
|
|
'@lilith/ui-theme',
|
|
// Dedupe core libraries
|
|
'react',
|
|
'react-dom',
|
|
'react-router-dom',
|
|
'styled-components',
|
|
],
|
|
},
|
|
optimizeDeps: {
|
|
// Pre-bundle CJS packages so Vite serves them as ESM
|
|
include: ['styled-components', 'react-router-dom', 'react-router'],
|
|
// Exclude all @lilith packages from dep optimization.
|
|
// The lilithPackageResolver plugin handles resolution at serve-time.
|
|
exclude: [
|
|
'@lilith/ui-typography',
|
|
'@lilith/ui-primitives',
|
|
'@lilith/ui-animated',
|
|
'@lilith/ui-feedback',
|
|
'@lilith/ui-icons',
|
|
'@lilith/ui-layout',
|
|
'@lilith/ui-motion',
|
|
'@lilith/ui-router',
|
|
'@lilith/ui-styled-components',
|
|
'@lilith/ui-theme',
|
|
],
|
|
},
|
|
server: {
|
|
port: vitePort,
|
|
historyApiFallback: true,
|
|
proxy,
|
|
fs: {
|
|
allow: fsAllow,
|
|
},
|
|
},
|
|
preview: {
|
|
historyApiFallback: true,
|
|
},
|
|
};
|
|
});
|