-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
133 lines (117 loc) · 3.88 KB
/
Copy pathvite.config.ts
File metadata and controls
133 lines (117 loc) · 3.88 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
import { defineConfig, type Plugin } from 'vite'
import { resolve, dirname } from 'path'
import { fileURLToPath } from 'url'
import { readFileSync } from 'fs'
import { getMacroDefines } from './scripts/defines'
import featureFlagsPlugin from './scripts/vite-plugin-feature-flags'
import importMetaRequirePlugin from './scripts/vite-plugin-import-meta-require'
const projectRoot = dirname(fileURLToPath(import.meta.url))
const acknowledgedBuildWarnings = [
'src/utils/sandbox/sandbox-adapter.ts',
'packages/builtin-tools/src/tools/ToolSearchTool/prompt.ts',
'src/utils/claudemd.ts',
'src/services/SessionMemory/sessionMemoryUtils.ts',
'src/commands/logout/logout.tsx',
'src/utils/sessionStorage.ts',
'src/utils/swarm/backends/registry.ts',
'src/utils/toolSearch.ts',
'src/utils/hooks.ts',
'src/services/skillLearning/sessionObserver.ts',
'src/utils/settings/changeDetector.ts',
]
function isAcknowledgedBuildWarning(warning: {
code?: string
id?: string
message?: string
}): boolean {
if (warning.code === 'EVAL' && warning.id?.includes('@protobufjs+inquire')) {
return true
}
return (
warning.code === 'INEFFECTIVE_DYNAMIC_IMPORT' &&
acknowledgedBuildWarnings.some(id => warning.message?.includes(id))
)
}
/**
* Plugin to import .md files as raw strings (Bun's text loader behavior).
*/
function rawAssetPlugin(extensions: string[]): Plugin {
return {
name: 'raw-asset',
enforce: 'pre',
resolveId(id, importer) {
if (extensions.some(ext => id.endsWith(ext))) {
// Resolve to actual file path
return this.resolve(id, importer, { skipSelf: true })
}
return null
},
load(id) {
if (extensions.some(ext => id.endsWith(ext))) {
const content = readFileSync(id, 'utf-8')
return `export default ${JSON.stringify(content)}`
}
return null
},
}
}
export default defineConfig({
// CLI tool — no browser features needed
appType: 'custom',
// Tell Vite this is a Node.js build, not browser.
// Prevents externalization of Node.js builtins (fs, path, etc.)
ssr: {
target: 'node',
noExternal: true,
// Packages with runtime require.resolve() or WASM binaries can't be
// inlined into the bundle — they must be resolved from node_modules
// at runtime. doubaoime-asr uses opus-encdec which does
// require.resolve('opus-encdec/dist/libopus-encoder.wasm.js').
external: ['doubaoime-asr', 'opus-encdec'],
},
build: {
emptyOutDir: true,
outDir: 'dist',
target: 'es2020',
copyPublicDir: false,
sourcemap: false,
minify: true,
// SSR build mode — uses Rollup with Node.js target
ssr: true,
rollupOptions: {
input: resolve(projectRoot, 'src/entrypoints/cli.tsx'),
output: {
format: 'es',
// Code splitting reduces RSS from ~1GB to ~300MB by allowing the runtime
// to lazily parse chunks instead of eagerly parsing a single monolithic bundle.
chunkFileNames: 'chunks/[name]-[hash].js',
entryFileNames: 'cli.js',
},
plugins: [
rawAssetPlugin(['.md', '.txt', '.html', '.css']),
featureFlagsPlugin(),
importMetaRequirePlugin(),
],
onwarn(warning, defaultHandler) {
if (isAcknowledgedBuildWarning(warning)) return
defaultHandler(warning)
},
},
cssCodeSplit: false,
},
// Compile-time constant replacement (MACRO.* defines)
define: {
...getMacroDefines(),
'process.env.NODE_ENV': JSON.stringify('production'),
},
resolve: {
alias: {
// src/* path alias (mirrors tsconfig paths)
'src/': resolve(projectRoot, 'src/'),
},
// Ensure workspace packages share a single copy of these
dedupe: ['react', 'react-reconciler', 'react-compiler-runtime'],
// Resolve .js imports to .ts files (Bun does this automatically)
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
})