forked from mihaip/infinite-mac
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
executable file
·98 lines (94 loc) · 3.12 KB
/
vite.config.ts
File metadata and controls
executable file
·98 lines (94 loc) · 3.12 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
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
95
96
97
98
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";
import { viteSingleFile } from "vite-plugin-singlefile"
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": ".",
"X-XSS-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
// Removed "X-Frame-Options": "DENY",
"Referrer-Policy": "unsafe-url",
"Feature-Policy": "none",
// Add Content-Security-Policy header
"Content-Security-Policy": "frame-ancestors *",
};
export default defineConfig(() => {
return {
build: {
assetsDir: ".",
assetsInlineLimit: 8192,
minify: false,
rollupOptions: {
output: {
inlineDynamicImports: true,
}
},
},
worker: {
format: "es",
},
assetsInclude: ["**/*.rom", "**/*.hda"],
server: {
port: 3127,
headers,
host: "0.0.0.0",
},
preview: {
port: 4127,
headers,
},
clearScreen: false,
plugins: [
basicSslWrapped(),
react(),
svgr(),
viteSingleFile(),
{
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,
};
}