-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
65 lines (64 loc) · 2.06 KB
/
vite.config.js
File metadata and controls
65 lines (64 loc) · 2.06 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
// vite.config.js
import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';
import topLevelAwait from 'vite-plugin-top-level-await';
// Set modern build target so top-level await in dependencies (e.g. three/examples WebGPU helper)
// doesn't get transformed to an unsupported lower target during bundle/transpile.
export default defineConfig({
plugins: [
wasm(),
topLevelAwait()
],
base: './',
build: {
target: 'es2022',
// Ensures assets don't get lost in complex folder structures
assetsDir: './',
// Restrict rollup input to only the app's root index.html so Vite doesn't try to
// analyze unrelated HTML files (like those under emsdk/tests) which can import
// non-app modules such as loader.mjs.
rollupOptions: {
input: {
main: './index.html'
}
}
},
esbuild: {
// ensure esbuild treats code as modern so top-level await is preserved
target: 'es2022'
},
// Ensure optimizeDeps only scans the app root entry (index.html) and targets
// modern JS (esnext) so top-level await in dependencies is preserved.
optimizeDeps: {
// Force dependency scanning to the app's root index -- don't scan test HTML files
// inside emsdk or other bundles which can include non-app imports.
entries: ['./index.html'],
esbuildOptions: {
target: 'esnext'
}
},
server: {
headers: {
// These headers are REQUIRED for SharedArrayBuffer (Pthreads)
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
// Keep Vite from serving files outside the repository root by default.
fs: {
strict: true
},
// Ignore the emsdk test folder (these are unrelated test HTML files that can
// confuse Vite's dependency scanner and cause unresolved import errors).
watch: {
ignored: ['**/emsdk/**']
}
},
// Ensure the worker file is treated correctly if using Vite's worker import (optional but safe)
worker: {
format: 'es',
plugins: () => [
wasm(),
topLevelAwait()
]
}
});