This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvite.config.ts
85 lines (82 loc) · 3.8 KB
/
vite.config.ts
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
import { defineConfig } from 'vite';
import * as path from 'path';
import * as fs from 'fs';
import url from 'url';
export default defineConfig(() => {
const config = {
build: {
target: 'esnext',
rollupOptions: {
input: {
index: path.resolve(__dirname, '/index.html'),
wrapperStatemachine: path.resolve(__dirname, '/packages/examples/wrapper_statemachine.html'),
wrapperLangium: path.resolve(__dirname, '/packages/examples/wrapper_langium.html'),
wrapperTs: path.resolve(__dirname, '/packages/examples/wrapper_ts.html'),
wrapperWebSocket: path.resolve(__dirname, '/packages/examples/wrapper_ws.html'),
wrapperAdvanced: path.resolve(__dirname, '/packages/examples/wrapper_adv.html'),
reactPython: path.resolve(__dirname, '/packages/examples/react_python.html'),
reactStatemachine: path.resolve(__dirname, '/packages/examples/react_statemachine.html'),
reactTs: path.resolve(__dirname, '/packages/examples/react_ts.html'),
workers: path.resolve(__dirname, '/packages/examples/workers.html'),
verifyWrapper: path.resolve(__dirname, '/packages/examples/verify_wrapper.html'),
verifyAlt: path.resolve(__dirname, '/packages/examples/verify_alt.html')
}
}
},
resolve: {
dedupe: ['monaco-editor', 'vscode']
},
server: {
origin: 'http://localhost:20001',
port: 20001
},
optimizeDeps: {
esbuildOptions: {
plugins: [
// copied from "https://github.com/CodinGame/monaco-vscode-api/blob/main/demo/vite.config.ts"
{
name: 'import.meta.url',
setup({ onLoad }) {
// Help vite that bundles/move files in dev mode without touching `import.meta.url` which breaks asset urls
onLoad({ filter: /.*\.js/, namespace: 'file' }, async args => {
const code = fs.readFileSync(args.path, 'utf8');
const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/g;
let i = 0;
let newCode = '';
for (let match = assetImportMetaUrlRE.exec(code); match != null; match = assetImportMetaUrlRE.exec(code)) {
newCode += code.slice(i, match.index);
const path = match[1].slice(1, -1);
const resolved = await import.meta.resolve!(path, url.pathToFileURL(args.path));
newCode += `new URL(${JSON.stringify(url.fileURLToPath(resolved))}, import.meta.url)`;
i = assetImportMetaUrlRE.lastIndex;
}
newCode += code.slice(i);
return { contents: newCode };
});
}
}
]
}
},
define: {
rootDirectory: JSON.stringify(__dirname)
},
test: {
pool: 'threads',
poolOptions: {
threads: {
isolate: true
}
},
browser: {
enabled: true,
headless: true,
name: 'chrome',
api: {
port: 20101
}
}
}
};
return config;
});