-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
94 lines (82 loc) · 2.31 KB
/
vite.config.ts
File metadata and controls
94 lines (82 loc) · 2.31 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
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig, PluginOption } from "vite";
import fs from "node:fs";
import sparkPlugin from "@github/spark/spark-vite-plugin";
import createIconImportProxy from "@github/spark/vitePhosphorIconProxyPlugin";
import { resolve } from 'path'
const workspaceRoot = resolve(process.cwd())
const projectRoot = process.env.PROJECT_ROOT || import.meta.dirname
const realProjectRoot = fs.realpathSync.native(projectRoot)
const manualChunks = (id: string) => {
if (!id.includes('node_modules')) {
return undefined
}
if (id.includes('react') || id.includes('scheduler')) {
return 'vendor-react'
}
if (id.includes('framer-motion') || id.includes('motion-dom') || id.includes('motion-utils')) {
return 'vendor-motion'
}
if (id.includes('@radix-ui')) {
return 'vendor-radix'
}
if (id.includes('@phosphor-icons')) {
return 'vendor-icons'
}
if (id.includes('i18next') || id.includes('react-i18next') || id.includes('html-parse-stringify') || id.includes('void-elements')) {
return 'vendor-i18n'
}
if (id.includes('jszip')) {
return 'vendor-zip'
}
if (id.includes('@github/spark')) {
return 'vendor-spark'
}
return undefined
}
// https://vite.dev/config/
export default defineConfig(({ command }) => ({
root: command === 'serve' ? realProjectRoot : undefined,
base: (() => { const b = process.env.BASE_URL ?? '/'; return b.endsWith('/') ? b : `${b}/`; })(),
plugins: [
react(),
tailwindcss(),
// DO NOT REMOVE
createIconImportProxy() as PluginOption,
sparkPlugin() as PluginOption,
],
resolve: {
preserveSymlinks: command === 'serve',
alias: {
'@': resolve(command === 'serve' ? realProjectRoot : projectRoot, 'src'),
}
},
server: {
fs: {
allow: [workspaceRoot, projectRoot, realProjectRoot],
},
},
optimizeDeps: command === 'serve' ? {
include: [
'react',
'react-dom',
'react-dom/client',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react-error-boundary',
'i18next',
'react-i18next',
'html-parse-stringify',
'void-elements',
],
} : undefined,
build: {
minify: 'esbuild',
rollupOptions: {
output: {
manualChunks,
},
},
},
}));