-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
71 lines (65 loc) · 2.03 KB
/
vite.config.js
File metadata and controls
71 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import path from 'path'
export default defineConfig(({ mode }) => {
// Load .env from parent directory (gnext_platform/)
const envDir = path.resolve(__dirname, '..')
const env = loadEnv(mode, envDir, '')
console.log
// Construct backend URL from VITE_BACKEND_PORT or fallback to VITE_API_URL
const backendPort = env.VITE_BACKEND_PORT || '8000'
const backendOrigin = env.VITE_API_URL || `http://localhost:${backendPort}`
const tsProto = 'http'
const tsHost = env.VITE_TYPESENSE_HOST || 'localhost'
const tsPort = env.VITE_TYPESENSE_PORT || '8108'
const typesenseOrigin = `${tsProto}://${tsHost}:${tsPort}`
const typesenseKey = env.VITE_TYPESENSE_KEY || ''
return {
envDir: envDir,
envPrefix: 'VITE_',
define: {
'process.env': env
},
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === 'drugst-one'
}
}
}),
vueDevTools()
],
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
// prevent bundling of the external web component <drugst-one>
build: {
rollupOptions: {
external: ['drugst-one'],
output: {
globals: {
'drugst-one': 'ELEMENT',
},
},
},
},
server: {
port: parseInt(env.VITE_FRONTEND_PORT || '5173'),
proxy: {
'/backend': { target: backendOrigin, changeOrigin: true },
'/typesense': {
target: typesenseOrigin,
changeOrigin: true,
// browser calls /typesense/... -> proxy sends to /...
rewrite: p => p.replace(/^\/typesense/, ''),
configure: proxy => {
proxy.on('proxyReq', req => {
if (typesenseKey) req.setHeader('X-TYPESENSE-API-KEY', typesenseKey)
})
},
},
},
},
}
})