forked from macaly/almostnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.sandbox.config.js
More file actions
69 lines (67 loc) · 1.87 KB
/
vite.sandbox.config.js
File metadata and controls
69 lines (67 loc) · 1.87 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import wasm from 'vite-plugin-wasm';
/**
* Vite config for the sandbox server.
*
* The sandbox is meant to be embedded in a cross-origin iframe,
* so we DON'T set COOP/COEP headers here (unlike the main app).
*/
export default defineConfig({
plugins: [
wasm(),
{
name: 'browser-shims',
enforce: 'pre',
resolveId(source) {
if (source === 'node:zlib' || source === 'zlib') {
return resolve(__dirname, 'src/shims/zlib.ts');
}
if (source === 'brotli-wasm/pkg.web/brotli_wasm.js') {
return resolve(__dirname, 'node_modules/brotli-wasm/pkg.web/brotli_wasm.js');
}
if (source === 'brotli-wasm/pkg.web/brotli_wasm_bg.wasm?url') {
return {
id: resolve(__dirname, 'node_modules/brotli-wasm/pkg.web/brotli_wasm_bg.wasm') + '?url',
external: false,
};
}
return null;
},
},
],
define: {
'process.env': {},
global: 'globalThis',
},
server: {
// Headers that allow this page to be embedded in a cross-origin iframe
// when the parent has Cross-Origin-Embedder-Policy set
headers: {
'Access-Control-Allow-Origin': '*',
'Cross-Origin-Resource-Policy': 'cross-origin',
},
fs: {
allow: [resolve(__dirname, './'), resolve(__dirname, 'node_modules')],
},
},
resolve: {
alias: {
'node:zlib': resolve(__dirname, 'src/shims/zlib.ts'),
'zlib': resolve(__dirname, 'src/shims/zlib.ts'),
'buffer': 'buffer',
'process': 'process/browser',
},
},
optimizeDeps: {
include: ['buffer', 'process', 'pako'],
exclude: ['brotli-wasm', 'convex'],
esbuildOptions: { target: 'esnext' },
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
assetsInclude: ['**/*.wasm'],
});