forked from TanStack/tanstack.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
129 lines (125 loc) · 3.65 KB
/
vite.config.ts
File metadata and controls
129 lines (125 loc) · 3.65 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { sentryVitePlugin } from '@sentry/vite-plugin'
import { defineConfig } from 'vite'
import contentCollections from '@content-collections/vite'
import tsConfigPaths from 'vite-tsconfig-paths'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import tailwindcss from '@tailwindcss/vite'
import { analyzer } from 'vite-bundle-analyzer'
import viteReact from '@vitejs/plugin-react'
import netlify from '@netlify/vite-plugin-tanstack-start'
const isDev = process.env.NODE_ENV !== 'production'
export default defineConfig({
server: {
port: Number(process.env.PORT) || 3000,
// WebContainer headers for /builder route (SharedArrayBuffer support)
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
// Watch linked @tanstack/cli for hot reload during development
watch: isDev
? {
ignored: ['!**/node_modules/@tanstack/cli/**'],
}
: undefined,
},
ssr: {
external: [
'postgres',
// CTA packages use execa which has a broken unicorn-magic dependency
'@tanstack/create',
// Externalize CLI so server reloads it on changes
'@tanstack/cli',
],
noExternal: ['drizzle-orm'],
},
optimizeDeps: {
exclude: [
'postgres',
// CTA packages use execa which has a broken unicorn-magic dependency
'@tanstack/create',
// Don't pre-bundle CLI so we always get fresh changes during dev
...(isDev ? ['@tanstack/cli'] : []),
],
},
build: {
sourcemap: process.env.NODE_ENV === 'production',
rollupOptions: {
external: (id) => {
// Externalize postgres from client bundle
return id.includes('postgres')
},
output: {
manualChunks: (id) => {
// Vendor chunk splitting for better caching
if (id.includes('node_modules')) {
// Search-related deps (only loaded when search modal opens)
if (
id.includes('algoliasearch') ||
id.includes('instantsearch') ||
id.includes('react-instantsearch')
) {
return 'search'
}
// Charting deps (only loaded on stats/admin pages)
if (
id.includes('@observablehq/plot') ||
(id.includes('d3') && !id.includes('d3-'))
) {
return 'd3-charts'
}
// Visualization deps
if (id.includes('@visx/')) {
return 'visx'
}
// Lucide icons (tree-shaken but still significant)
if (id.includes('lucide-react')) {
return 'icons'
}
}
},
},
},
},
plugins: [
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
tanstackStart({
router: {
codeSplittingOptions: {
defaultBehavior: [
[
'component',
'pendingComponent',
'errorComponent',
'notFoundComponent',
'loader',
],
],
},
},
}),
// Only enable Netlify plugin during build or when NETLIFY env is set
...(process.env.NETLIFY || process.env.NODE_ENV === 'production'
? [netlify()]
: []),
viteReact(),
sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'tanstack',
project: 'tanstack-com',
}),
contentCollections(),
tailwindcss(),
...(process.env.ANALYZE
? [
analyzer({
analyzerMode: 'json',
fileName: 'bundle-analysis',
defaultSizes: 'stat',
}),
]
: []),
],
})