forked from abh1nash/ace-daw
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathvite.config.ts
More file actions
147 lines (142 loc) · 6.52 KB
/
vite.config.ts
File metadata and controls
147 lines (142 loc) · 6.52 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { resolve } from 'path';
import { copyFileSync, existsSync } from 'fs';
const apiTarget = process.env.VITE_API_TARGET || 'http://127.0.0.1:8001';
const serverPort = Number(process.env.VITE_PORT) || 5174;
export default defineConfig(async ({ command }) => {
// Only load Claude terminal plugin in dev mode — it uses node-pty (native module)
const plugins = [react(), tailwindcss()];
if (command === 'serve') {
const { claudeTerminalPlugin } = await import('./server/vite-plugin-claude-terminal');
plugins.push(claudeTerminalPlugin());
}
// Copy WASM binaries to public/ so they can be served as static assets
const wasmFiles: [string, string][] = [
['src/wasm/pkg/ace_dsp_wasm_bg.wasm', 'public/ace_dsp_wasm_bg.wasm'],
['src/wasm/waveform-pkg/ace_waveform_wasm_bg.wasm', 'public/ace_waveform_wasm_bg.wasm'],
['node_modules/rubberband-wasm/dist/rubberband.wasm', 'public/rubberband.wasm'],
];
for (const [src, dest] of wasmFiles) {
const srcPath = resolve(__dirname, src);
const destPath = resolve(__dirname, dest);
if (existsSync(srcPath)) {
copyFileSync(srcPath, destPath);
}
}
return {
plugins,
optimizeDeps: {
exclude: ['onnxruntime-web'],
},
build: {
// DAW apps intentionally ship large lazy-loaded audio/editor chunks; the
// manualChunks map below keeps hot-path app code split while allowing
// known-heavy editor/audio vendors such as Strudel to exceed 500KB.
chunkSizeWarningLimit: 1200,
rollupOptions: {
output: {
manualChunks(rawId: string) {
// Normalize path separators for Windows compatibility
const id = rawId.replace(/\\/g, '/');
// Tone.js — large audio synthesis library (~800 KB)
if (id.includes('node_modules/tone/') || id.includes('node_modules/standardized-audio-context/')) {
return 'vendor-tone';
}
// Strudel — live-coding pattern language, split into sub-chunks
// draw depends only on core, used by both webaudio and codemirror
if (id.includes('node_modules/@strudel/core/') || id.includes('node_modules/@strudel/mini/') || id.includes('node_modules/@strudel/tonal/') || id.includes('node_modules/@strudel/draw/')) {
return 'vendor-strudel-core';
}
if (id.includes('node_modules/@strudel/webaudio/') || id.includes('node_modules/@strudel/soundfonts/') || id.includes('node_modules/superdough/') || id.includes('node_modules/supradough/')) {
return 'vendor-strudel-audio';
}
if (id.includes('node_modules/@strudel/codemirror/') || id.includes('node_modules/@strudel/transpiler/')) {
return 'vendor-strudel-editor';
}
if (id.includes('node_modules/@strudel/')) {
return 'vendor-strudel-misc';
}
// CodeMirror — split into core and extensions
if (id.includes('node_modules/@codemirror/state/') || id.includes('node_modules/@codemirror/view/') || id.includes('node_modules/@lezer/') || id.includes('node_modules/codemirror/')) {
return 'vendor-codemirror-core';
}
if (id.includes('node_modules/@codemirror/')) {
return 'vendor-codemirror-ext';
}
// Replit codemirror keybinding extensions (vim, emacs, vscode)
if (id.includes('node_modules/@replit/codemirror-')) {
return 'vendor-codemirror-keymaps';
}
// xterm — terminal emulation (already somewhat split, ensure isolation)
if (id.includes('node_modules/xterm/') || id.includes('node_modules/@xterm/')) {
return 'vendor-xterm';
}
// Video processing — mp4-muxer + web-demuxer
if (id.includes('node_modules/mp4-muxer/') || id.includes('node_modules/web-demuxer/')) {
return 'vendor-video';
}
// React core — react, react-dom, scheduler
if (id.includes('node_modules/react/') || id.includes('node_modules/react-dom/') || id.includes('node_modules/scheduler/')) {
return 'vendor-react';
}
// Audio engine layer — force into dedicated chunks
// Shared by many lazy components; prevent Rollup from promoting to entry chunk
// Effects engine — largest engine module, separate chunk
if ((id.includes('/src/engine/EffectsEngine') || id.includes('/src/engine/dsp/')) && !id.includes('__tests__')) {
return 'app-engine-fx';
}
// Export/offline rendering — only needed for bounce/export operations
if ((id.includes('/src/engine/exportMix') || id.includes('/src/engine/offlineRender')) && !id.includes('__tests__')) {
return 'app-engine-export';
}
// Core audio engine + remaining modules
if (id.includes('/src/engine/') && !id.includes('__tests__')) {
return 'app-engine';
}
if (id.includes('/src/hooks/useAudioEngine') || id.includes('/src/hooks/useTransport.ts') || id.includes('/src/hooks/useEffectsSync') || id.includes('/src/hooks/useRecording')) {
return 'app-engine';
}
},
},
},
},
worker: {
format: 'es',
},
resolve: {
alias: {
// Stub out @kabelsalat/web — Strudel's optional modular synth engine
// has a broken export in v0.4.1. We don't use it; we use queryArc only.
'@kabelsalat/web': resolve(__dirname, 'src/stubs/kabelsalat-web.ts'),
},
},
server: {
host: '127.0.0.1',
port: serverPort,
strictPort: true,
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
proxy: {
'/api': {
target: apiTarget,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
timeout: 5 * 60 * 1000,
proxyTimeout: 5 * 60 * 1000,
configure: (proxy) => {
proxy.on('error', (_err, _req, res) => {
if (res && 'writeHead' in res && !res.headersSent) {
res.writeHead(502, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Backend unavailable' }));
}
});
},
},
},
},
};
});