yangdx commited on
Commit
593d58c
·
1 Parent(s): 7b784d0

Refactor Vite configuration and add environment type definitions

Browse files

- Removed local Vite config file
- Updated dev scripts to use default config
- Added env.d.ts for type definitions
- Enhanced Vite config with dynamic proxy
- Simplified build and dev script commands

lightrag_webui/package.json CHANGED
@@ -4,11 +4,11 @@
4
  "version": "0.0.0",
5
  "type": "module",
6
  "scripts": {
7
- "dev": "bunx --bun vite --config vite.config.local.js",
8
  "build": "bunx --bun vite build",
9
  "lint": "eslint .",
10
  "preview": "bunx --bun vite preview",
11
- "dev-no-bun": "vite --config vite.config.local.js",
12
  "build-no-bun": "vite build --emptyOutDir",
13
  "preview-no-bun": "vite preview"
14
  },
 
4
  "version": "0.0.0",
5
  "type": "module",
6
  "scripts": {
7
+ "dev": "bunx --bun vite",
8
  "build": "bunx --bun vite build",
9
  "lint": "eslint .",
10
  "preview": "bunx --bun vite preview",
11
+ "dev-no-bun": "vite",
12
  "build-no-bun": "vite build --emptyOutDir",
13
  "preview-no-bun": "vite preview"
14
  },
lightrag_webui/src/env.d.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ /// <reference types="vite/client" />
2
+
3
+ interface ImportMetaEnv {
4
+ readonly VITE_API_PROXY: string
5
+ readonly VITE_API_ENDPOINTS: string
6
+ readonly VITE_BACKEND_URL: string
7
+ }
lightrag_webui/vite.config.local.js DELETED
@@ -1,38 +0,0 @@
1
- import { defineConfig } from 'vite'
2
- import baseConfig from './vite.config'
3
- import { mergeConfig } from 'vite'
4
-
5
- export default mergeConfig(
6
- baseConfig,
7
- defineConfig({
8
- server: {
9
- proxy: {
10
- '/api': {
11
- target: 'http://localhost:9621',
12
- changeOrigin: true,
13
- rewrite: (path) => path.replace(/^\/api/, '')
14
- },
15
- '/documents': {
16
- target: 'http://localhost:9621',
17
- changeOrigin: true
18
- },
19
- '/graphs': {
20
- target: 'http://localhost:9621',
21
- changeOrigin: true
22
- },
23
- '/graph': {
24
- target: 'http://localhost:9621',
25
- changeOrigin: true
26
- },
27
- '/health': {
28
- target: 'http://localhost:9621',
29
- changeOrigin: true
30
- },
31
- '/query': {
32
- target: 'http://localhost:9621',
33
- changeOrigin: true
34
- }
35
- }
36
- }
37
- })
38
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lightrag_webui/vite.config.ts CHANGED
@@ -16,5 +16,19 @@ export default defineConfig({
16
  build: {
17
  outDir: path.resolve(__dirname, '../lightrag/api/webui'),
18
  emptyOutDir: true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
20
  })
 
16
  build: {
17
  outDir: path.resolve(__dirname, '../lightrag/api/webui'),
18
  emptyOutDir: true
19
+ },
20
+ server: {
21
+ proxy: import.meta.env.VITE_API_PROXY === 'true' && import.meta.env.VITE_API_ENDPOINTS ?
22
+ Object.fromEntries(
23
+ import.meta.env.VITE_API_ENDPOINTS.split(',').map(endpoint => [
24
+ endpoint,
25
+ {
26
+ target: import.meta.env.VITE_BACKEND_URL || 'http://localhost:9621',
27
+ changeOrigin: true,
28
+ rewrite: endpoint === '/api' ?
29
+ (path) => path.replace(/^\/api/, '') : undefined
30
+ }
31
+ ])
32
+ ) : {}
33
  }
34
  })