2025-02-09 23:15:26 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import path from 'path'
|
2025-03-14 17:00:36 +08:00
|
|
|
import { webuiPrefix } from '@/lib/constants'
|
2025-02-09 23:15:26 +08:00
|
|
|
import react from '@vitejs/plugin-react-swc'
|
|
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
|
|
|
|
|
|
// https://vite.dev/config/
|
|
|
|
export default defineConfig({
|
|
|
|
plugins: [react(), tailwindcss()],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': path.resolve(__dirname, './src')
|
|
|
|
}
|
|
|
|
},
|
2025-03-14 17:00:36 +08:00
|
|
|
// base: import.meta.env.VITE_BASE_URL || '/webui/',
|
|
|
|
base: webuiPrefix,
|
2025-02-13 17:53:12 +08:00
|
|
|
build: {
|
2025-03-05 12:54:15 +08:00
|
|
|
outDir: path.resolve(__dirname, '../lightrag/api/webui'),
|
2025-04-22 16:38:35 +08:00
|
|
|
emptyOutDir: true,
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
// Manual chunking strategy
|
|
|
|
manualChunks: {
|
|
|
|
// Group React-related libraries into one chunk
|
|
|
|
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
|
|
|
|
// Group graph visualization libraries into one chunk
|
|
|
|
'graph-vendor': ['sigma', 'graphology', '@react-sigma/core'],
|
|
|
|
// Group UI component libraries into one chunk
|
|
|
|
'ui-vendor': ['@radix-ui/react-dialog', '@radix-ui/react-popover', '@radix-ui/react-select', '@radix-ui/react-tabs'],
|
|
|
|
// Group utility libraries into one chunk
|
|
|
|
'utils-vendor': ['axios', 'i18next', 'zustand', 'clsx', 'tailwind-merge'],
|
|
|
|
// Separate feature modules
|
|
|
|
'feature-graph': ['./src/features/GraphViewer'],
|
|
|
|
'feature-documents': ['./src/features/DocumentManager'],
|
2025-04-22 16:47:39 +08:00
|
|
|
'feature-retrieval': ['./src/features/RetrievalTesting'],
|
2025-04-22 18:34:30 +08:00
|
|
|
|
2025-04-22 16:47:39 +08:00
|
|
|
// Mermaid-related modules
|
|
|
|
'mermaid-vendor': ['mermaid'],
|
2025-04-22 17:21:24 +08:00
|
|
|
|
2025-04-22 16:47:39 +08:00
|
|
|
// Markdown-related modules
|
|
|
|
'markdown-vendor': [
|
|
|
|
'react-markdown',
|
|
|
|
'rehype-react',
|
|
|
|
'remark-gfm',
|
|
|
|
'remark-math',
|
|
|
|
'react-syntax-highlighter'
|
|
|
|
]
|
2025-04-22 16:38:35 +08:00
|
|
|
},
|
|
|
|
// Ensure consistent chunk naming format
|
|
|
|
chunkFileNames: 'assets/[name]-[hash].js',
|
|
|
|
// Entry file naming format
|
|
|
|
entryFileNames: 'assets/[name]-[hash].js',
|
|
|
|
// Asset file naming format
|
|
|
|
assetFileNames: 'assets/[name]-[hash].[ext]'
|
|
|
|
}
|
|
|
|
}
|
2025-03-05 18:25:51 +08:00
|
|
|
},
|
|
|
|
server: {
|
2025-03-07 08:17:25 +08:00
|
|
|
proxy: import.meta.env.VITE_API_PROXY === 'true' && import.meta.env.VITE_API_ENDPOINTS ?
|
2025-03-05 18:25:51 +08:00
|
|
|
Object.fromEntries(
|
|
|
|
import.meta.env.VITE_API_ENDPOINTS.split(',').map(endpoint => [
|
|
|
|
endpoint,
|
|
|
|
{
|
|
|
|
target: import.meta.env.VITE_BACKEND_URL || 'http://localhost:9621',
|
|
|
|
changeOrigin: true,
|
2025-03-07 08:17:25 +08:00
|
|
|
rewrite: endpoint === '/api' ?
|
2025-03-13 12:38:33 +08:00
|
|
|
(path) => path.replace(/^\/api/, '') :
|
|
|
|
endpoint === '/docs' || endpoint === '/openapi.json' ?
|
|
|
|
(path) => path : undefined
|
2025-03-05 18:25:51 +08:00
|
|
|
}
|
|
|
|
])
|
|
|
|
) : {}
|
2025-02-13 17:53:12 +08:00
|
|
|
}
|
2025-02-10 00:33:39 +08:00
|
|
|
})
|