-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathvite.config.ts
More file actions
135 lines (131 loc) · 4.1 KB
/
Copy pathvite.config.ts
File metadata and controls
135 lines (131 loc) · 4.1 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
import { defineConfig, type Plugin } from 'vite'
import react from '@vitejs/plugin-react'
import { APP_VERSION } from './src/version'
import path from 'path'
import {
allowedFileRoots,
bridgeToken,
createDevBridgePlugin,
} from './tools/devBridge/vitePlugin.ts'
function splatTransformWebpWasmPathFix(): Plugin {
return {
name: 'splat-transform-webp-wasm-path-fix',
enforce: 'pre',
transform(code, id) {
const normalizedId = id.replace(/\\/g, '/');
if (!normalizedId.endsWith('/node_modules/@playcanvas/splat-transform/dist/index.mjs')) {
return null;
}
return code.replace(
/new URL\("webp\.wasm",\s*import\.meta\.url\)\.href/g,
'new URL("../lib/webp.wasm", import.meta.url).href',
);
},
};
}
// https://vite.dev/config/
export default defineConfig(({ command, mode }) => {
const isDevServer = command === 'serve';
const enableDevBridge = isDevServer && mode !== 'test';
const freezeE2eSourceSnapshot = process.env.MASTERSELECTS_E2E_FREEZE_SOURCE === '1';
const hostedApiProxyTarget = 'http://127.0.0.1:8788';
const hostedApiProxyRoutes = [
'/api/me',
'/api/auth',
'/api/billing',
'/api/credits',
'/api/support',
'/api/stripe',
'/api/ai/chat',
'/api/ai/audio',
'/api/ai/video',
'/api/kernel',
'/api/visits',
'/api/admin',
];
const hostedApiProxy = Object.fromEntries(
hostedApiProxyRoutes.map((route) => [
route,
{
changeOrigin: false,
target: hostedApiProxyTarget,
},
]),
);
return {
plugins: [
react(),
createDevBridgePlugin({ enableAiToolsBridge: enableDevBridge }),
splatTransformWebpWasmPathFix(),
// Replace __APP_VERSION__ in index.html during build
{
name: 'html-version-replace',
transformIndexHtml(html) {
return html.replace(/__APP_VERSION__/g, APP_VERSION);
},
},
],
resolve: {
alias: {
module: path.resolve(__dirname, 'src/shims/nodeModule.ts'),
},
},
define: {
__APP_VERSION__: JSON.stringify(APP_VERSION),
// Show changelog in the app by default; tests override this separately.
__SHOW_CHANGELOG__: true,
__DEV_BRIDGE_TOKEN__: JSON.stringify(isDevServer ? bridgeToken : ''),
__DEV_ALLOWED_FILE_ROOTS__: JSON.stringify(isDevServer ? allowedFileRoots : []),
},
server: {
allowedHosts: ['localhost', '.localhost', '127.0.0.1'],
// Keep a headed release journey on the source snapshot it booted with.
// The dev bridge still uses Vite's websocket; only filesystem-triggered
// HMR/full reloads are suppressed for this isolated test server.
watch: freezeE2eSourceSnapshot ? { ignored: ['**/*'] } : undefined,
headers: {
// Required for SharedArrayBuffer (FFmpeg multi-threaded, cross-tab sync)
// Using 'credentialless' instead of 'require-corp' to allow CDN resources
// (FFmpeg WASM from unpkg, transformers.js from HuggingFace)
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'credentialless',
},
proxy: hostedApiProxy,
},
preview: {
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'credentialless',
},
},
worker: {
// Runtime-host workers import split chunks, which requires the ES module format.
format: 'es',
},
build: {
target: 'esnext',
chunkSizeWarningLimit: 6000,
rollupOptions: {
onwarn(warning, warn) {
if (warning.message.includes('dynamic import will not move module into another chunk')) {
return;
}
warn(warning);
},
output: {
manualChunks: {
// Force heavy libs into separate chunks (loaded on demand)
'mp4box': ['mp4box'],
},
},
},
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
// Exclude transformers.js and onnxruntime from pre-bundling
exclude: ['@huggingface/transformers', 'onnxruntime-web'],
},
};
})