-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
98 lines (85 loc) · 3.5 KB
/
vite.config.ts
File metadata and controls
98 lines (85 loc) · 3.5 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { resolve } from 'path'
import { existsSync } from 'fs'
import { clientConfig } from './config/system/client.config'
import { fluxstackVitePlugins } from './core/build/vite-plugins'
// Root directory (vite.config.ts is in project root)
const rootDir = import.meta.dirname
// When using bun-linked @fluxstack/live-* packages locally, point Vite at the
// TypeScript source instead of pre-built dist. This ensures a single React
// context (no dual-instance problem) and gives us HMR for the library code.
// In CI or when the sibling repo doesn't exist, resolve from node_modules.
const liveMonorepoRoot = resolve(rootDir, '../fluxstack-live/packages')
const hasLocalLiveMonorepo = existsSync(resolve(liveMonorepoRoot, 'core/src/index.ts'))
const liveAliases: Record<string, string> = hasLocalLiveMonorepo
? {
'@fluxstack/live-react': resolve(liveMonorepoRoot, 'react/src/index.ts'),
'@fluxstack/live-client': resolve(liveMonorepoRoot, 'client/src/index.ts'),
'@fluxstack/live': resolve(liveMonorepoRoot, 'core/src/index.ts'),
}
: {}
// https://vite.dev/config/
export default defineConfig({
plugins: [
// FluxStack internal plugins (live-strip, tsconfig-paths, type-checker)
...fluxstackVitePlugins(),
react(),
tailwindcss(),
],
root: resolve(rootDir, 'app/client'),
// Aliases são lidos do tsconfig.json pelo plugin vite-tsconfig-paths
resolve: {
dedupe: ['react', 'react-dom', 'react/jsx-runtime'],
alias: liveAliases,
},
// Exclude linked packages from dep optimization when aliased to source
optimizeDeps: {
exclude: hasLocalLiveMonorepo
? ['@fluxstack/live', '@fluxstack/live-client', '@fluxstack/live-react']
: [],
},
server: {
port: clientConfig.vite.port, // ✅ From config
host: clientConfig.vite.host, // ✅ From config
strictPort: clientConfig.vite.strictPort, // ✅ From config
open: clientConfig.vite.open, // ✅ From config
allowedHosts: clientConfig.vite.allowedHosts, // ✅ From config (VITE_ALLOWED_HOSTS)
// Allow Vite to serve files outside the client root (needed for monorepo aliases)
fs: {
allow: [
rootDir,
...(hasLocalLiveMonorepo ? [liveMonorepoRoot] : []),
],
},
hmr: {
protocol: 'ws',
host: clientConfig.vite.host,
port: clientConfig.vite.port,
clientPort: clientConfig.vite.port
},
proxy: {
'/api/': {
target: 'http://localhost:3000',
changeOrigin: true,
// WebSocket goes directly to port 3000 (configured in App.tsx)
// to avoid Vite proxy overhead and HMR contention
},
'/swagger': {
target: 'http://localhost:3000',
changeOrigin: true,
},
}
},
build: {
target: clientConfig.build.target, // ✅ From config
outDir: resolve(rootDir, clientConfig.build.outDir ?? 'dist/client'), // ✅ From config
sourcemap: clientConfig.build.sourceMaps, // ✅ From config
minify: clientConfig.build.minify, // ✅ From config
assetsDir: clientConfig.build.assetsDir, // ✅ From config
cssCodeSplit: clientConfig.build.cssCodeSplit, // ✅ From config
chunkSizeWarningLimit: clientConfig.build.chunkSizeWarningLimit, // ✅ From config
emptyOutDir: clientConfig.build.emptyOutDir // ✅ From config
}
})