-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
vite.config.ts
87 lines (84 loc) · 2.67 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
import {type ResolvedConfig, defineConfig} from "vite";
import react from "@vitejs/plugin-react-swc";
import basicSsl from "@vitejs/plugin-basic-ssl";
import svgr from "vite-plugin-svgr";
import {viteDevMiddleware} from "./src/vite-dev-middleware";
const headers = {
// Allow SharedArrayBuffer to work locally
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
// Allow the service worker to intercept all paths, even when
// initiated from a year subpath.
"Service-Worker-Allowed": "/",
};
export default defineConfig(() => {
return {
build: {
outDir: "build",
minify: true,
},
worker: {
format: "es",
},
assetsInclude: [
"**/*.rom",
"**/*.hda",
"**/*nvram.bin",
"**/*pram.bin",
],
server: {
port: 3127,
headers,
host: "0.0.0.0",
},
preview: {
port: 4127,
headers,
},
clearScreen: false,
plugins: [
basicSslWrapped(),
react(),
svgr(),
{
name: "dev-middleware",
configureServer: server => {
// Add stubs for the functionality provided by the
// Cloudflare worker.
server.middlewares.use((req, res, next) => {
const handled = viteDevMiddleware(req, res);
if (!handled) {
next();
}
});
},
},
],
};
});
// The basicSsl() plugin will set up https for both dev/serve and preview, but we only
// want it for the latter. The plugin doesn't support options
// (https://github.com/vitejs/vite-plugin-basic-ssl/issues/9), so we instead
// wrap it and undo the dev/serve https config after it's done.
function basicSslWrapped() {
const originalBasicSsl = basicSsl();
let configResolved:
| ((config: ResolvedConfig) => void | Promise<void>)
| undefined;
const {configResolved: originalConfigResolved} = originalBasicSsl;
if (typeof originalConfigResolved === "function") {
configResolved = function (config) {
const originalResult = originalConfigResolved(config);
if (originalResult instanceof Promise) {
return originalResult.then(() => {
delete config.server.https;
});
}
delete config.server.https;
};
}
return {
...originalBasicSsl,
configResolved,
};
}