-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvite.config.ts
More file actions
217 lines (212 loc) · 6.05 KB
/
vite.config.ts
File metadata and controls
217 lines (212 loc) · 6.05 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import { reactRouter } from '@react-router/dev/vite';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import { visualizer } from 'rollup-plugin-visualizer';
import UnoCSS from 'unocss/vite';
import type { PluginOption } from 'vite';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig((config) => {
return {
server: {
fs: {
/*
* Allow serving files when ?url= query param is used. Vite reserves ?url for
* its module system, which conflicts with our template import ?url=https://... pattern.
*/
strict: false,
},
},
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
build: {
target: 'esnext',
sourcemap: true,
rollupOptions: {
// Externalize undici and util/types for client builds - these are server-only modules
external: ['undici', 'util/types', 'node:util/types'],
},
},
resolve: {
dedupe: [
'react',
'react-dom',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react-dom/client',
'react-router',
'@nanostores/react',
],
alias: {
// Provide empty shim for util/types in client builds
'util/types': 'rollup-plugin-node-polyfills/polyfills/empty',
'node:util/types': 'rollup-plugin-node-polyfills/polyfills/empty',
},
},
ssr: {
// Use native Node.js modules for SSR - don't polyfill these
noExternal: [],
external: [
'stream',
'node:stream',
'util',
'util/types',
'node:util',
'node:util/types',
'buffer',
'node:buffer',
'react-window',
],
},
plugins: [
nodePolyfills({
include: ['buffer', 'process', 'util'],
globals: {
Buffer: true,
process: true,
global: true,
},
protocolImports: true,
exclude: ['child_process', 'fs', 'path', 'stream'],
}),
{
name: 'buffer-polyfill',
transform(code: string, id: string) {
if (id.includes('env.mjs')) {
return {
code: `import { Buffer } from 'buffer';\n${code}`,
map: null,
};
}
return null;
},
},
reactRouter(),
UnoCSS(),
tsconfigPaths(),
config.mode === 'production' && optimizeCssModules({ apply: 'build' }),
process.env.ANALYZE
? visualizer({
filename: 'stats.html',
open: true,
gzipSize: true,
brotliSize: true,
})
: false,
config.mode === 'production' &&
process.env.SENTRY_AUTH_TOKEN &&
sentryVitePlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
filesToDeleteAfterUpload: ['./build/**/*.map'],
},
telemetry: false,
}),
].filter(Boolean) as PluginOption[],
envPrefix: [
'VITE_',
'OPENAI_LIKE_API_BASE_URL',
'OPENAI_LIKE_API_MODELS',
'OLLAMA_API_BASE_URL',
'LMSTUDIO_API_BASE_URL',
'TOGETHER_API_BASE_URL',
'SENTRY_DSN',
],
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
optimizeDeps: {
include: [
/*
* Pre-bundle all known client deps at startup to avoid runtime discovery + page reload.
* Without this, Vite discovers ~40 deps during first page load, re-bundles, and forces a reload.
*
* React + React-DOM MUST be listed here so that all other pre-bundled deps share
* the same React internals instead of inlining a separate copy.
*/
'react',
'react-dom',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react-dom/client',
'react-dnd',
'react-dnd-html5-backend',
'@ai-sdk/react',
'@nanostores/react',
'framer-motion',
'react-toastify',
'react-markdown',
'react-resizable-panels',
'react-window',
'react-qrcode-logo',
'react-chartjs-2',
'class-variance-authority',
'date-fns',
'diff',
'dompurify',
'shiki',
'chart.js',
'file-saver',
'jspdf',
'jszip',
'ignore',
'istextorbinary',
'js-cookie',
'nanostores',
'path-browserify',
'mime',
'rehype-raw',
'rehype-sanitize',
'remark-gfm',
'unist-util-visit',
'isomorphic-git',
/* Radix UI */
'@radix-ui/react-checkbox',
'@radix-ui/react-collapsible',
'@radix-ui/react-context-menu',
'@radix-ui/react-dialog',
'@radix-ui/react-dropdown-menu',
'@radix-ui/react-label',
'@radix-ui/react-popover',
'@radix-ui/react-scroll-area',
'@radix-ui/react-separator',
'@radix-ui/react-switch',
'@radix-ui/react-tabs',
'@radix-ui/react-tooltip',
'@radix-ui/react-visually-hidden',
/* CodeMirror */
'@codemirror/autocomplete',
'@codemirror/commands',
'@codemirror/lang-cpp',
'@codemirror/lang-css',
'@codemirror/lang-html',
'@codemirror/lang-javascript',
'@codemirror/lang-json',
'@codemirror/lang-markdown',
'@codemirror/lang-python',
'@codemirror/lang-sass',
'@codemirror/lang-vue',
'@codemirror/lang-wast',
'@codemirror/language',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@uiw/codemirror-theme-vscode',
'@lezer/highlight',
/* Terminal */
'@xterm/addon-fit',
'@xterm/addon-web-links',
'@xterm/xterm',
],
exclude: ['undici'],
},
};
});