-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.mjs
More file actions
75 lines (71 loc) · 2.46 KB
/
Copy pathvite.config.mjs
File metadata and controls
75 lines (71 loc) · 2.46 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
72
73
74
75
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { fileURLToPath } from 'url'
import navDiscovery from './build/vite-plugin-nav-discovery.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
/**
* Create a Vite config for Org Pulse.
*
* Dual-root resolution model:
* - @/ and @shared resolve from coreDir (this package)
* - @modules and @platform resolve from projectRoot (consumer)
* - import.meta.glob absolute paths resolve from root (projectRoot)
*
* @param {{ root?: string, aliases?: Record<string, string> }} options
*/
export function createViteConfig(options = {}) {
const coreDir = __dirname
const projectRoot = options.root || process.cwd()
return defineConfig({
root: projectRoot,
plugins: [
vue(),
navDiscovery()
],
resolve: {
alias: {
'@/': path.resolve(coreDir, 'src') + '/',
'@shared': path.resolve(coreDir, 'shared'),
'@modules': path.resolve(projectRoot, 'modules'),
'@platform': path.resolve(projectRoot, 'platform'),
...options.aliases
}
},
server: {
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true
},
'/modules': {
target: 'http://localhost:3001',
changeOrigin: true,
// Only proxy requests for git-static module content (HTML, assets).
// Let Vite serve source files from the modules/ directory (for import.meta.glob).
bypass(req) {
const pathOnly = (req.url || '').split('?')[0]
// Static HTML under modules/ (e.g. quality reports imported with ?url) must be served by Vite, not the API.
if (/\.html$/i.test(pathOnly)) {
return req.url
}
const accept = req.headers.accept || ''
// Vite module requests have JS accept headers or ?import/?t= query strings
if (accept.includes('application/javascript') ||
req.url.includes('?import') ||
req.url.includes('?t=') ||
req.url.includes('.vue?') ||
req.url.endsWith('.json') ||
req.url.endsWith('.js') ||
req.url.endsWith('.css') ||
req.url.endsWith('.vue')) {
return req.url
}
}
}
}
}
})
}
// Default export for standalone use (core repo development)
export default createViteConfig()