-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
94 lines (90 loc) · 2.61 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
86
87
88
89
90
91
92
93
94
import { defineConfig } from "vite";
import importMetaUrlPlugin from "@codingame/esbuild-import-meta-url-plugin";
import * as fs from "fs";
import path from "path";
import tsconfigPaths from "vite-tsconfig-paths";
const proxyTarget = `http://localhost:${process.env.PORT}`;
export default defineConfig({
build: {
target: "esnext",
rollupOptions: {
external: ["~lib"],
},
},
server: {
port: 3000,
host: "0.0.0.0",
proxy: {
"/auth": {
target: proxyTarget,
changeOrigin: true,
},
"/api": {
target: proxyTarget,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ""),
},
},
},
plugins: [
tsconfigPaths(),
{
// For the *-language-features extensions which use SharedArrayBuffer
name: "configure-response-headers",
apply: "serve",
configureServer: server => {
server.middlewares.use((_req, res, next) => {
res.setHeader("Cross-Origin-Embedder-Policy", "credentialless");
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
next();
});
},
},
{
name: "force-prevent-transform-assets",
apply: "serve",
configureServer(server) {
return () => {
server.middlewares.use(async (req, res, next) => {
if (req.originalUrl != null) {
const pathname = new URL(req.originalUrl, import.meta.url)
.pathname;
if (pathname.endsWith(".html")) {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.write(fs.readFileSync(path.join(__dirname, pathname)));
res.end();
}
}
next();
});
};
},
},
],
optimizeDeps: {
include: [
"vscode/extensions",
"vscode/services",
"vscode/monaco",
"vscode/localExtensionHost",
// These 2 lines prevent vite from reloading the whole page when starting a worker (so 2 times in a row after cleaning the vite cache - for the editor then the textmate workers)
// it's mainly empirical and probably not the best way, fix me if you find a better way
"vscode-textmate",
"vscode-oniguruma",
"@vscode/vscode-languagedetection",
],
exclude: ["@electric-sql/pglite"],
esbuildOptions: {
tsconfig: "./tsconfig.json",
plugins: [importMetaUrlPlugin],
},
},
define: {
rootDirectory: JSON.stringify(__dirname),
},
resolve: {
dedupe: ["vscode"],
},
});