-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvite.config.ts
More file actions
99 lines (91 loc) · 2.56 KB
/
Copy pathvite.config.ts
File metadata and controls
99 lines (91 loc) · 2.56 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
99
import { readFile } from "node:fs/promises";
import { type IncomingMessage, type ServerResponse } from "node:http";
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite-plus";
const staticPageNames = ["apps", "merch", "tv"] as const;
const devStaticPageHtml = new Map(
staticPageNames.map((name) => [
name,
fileURLToPath(new URL(`./public/${name}/index.html`, import.meta.url)),
]),
);
const previewStaticPageHtml = new Map(
staticPageNames.map((name) => [
name,
fileURLToPath(new URL(`./dist/${name}/index.html`, import.meta.url)),
]),
);
type MiddlewareNext = (error?: unknown) => void;
function getStaticPageName(url: string | undefined) {
const { pathname } = new URL(url ?? "/", "http://localhost");
return staticPageNames.find((name) => pathname === `/${name}` || pathname === `/${name}/`);
}
function serveStaticPage(pathnames: ReadonlyMap<string, string>) {
return async (request: IncomingMessage, response: ServerResponse, next: MiddlewareNext) => {
const pageName = getStaticPageName(request.url);
const pathname = pageName ? pathnames.get(pageName) : undefined;
if (!pathname) {
next();
return;
}
try {
const html = await readFile(pathname, "utf8");
response.statusCode = 200;
response.setHeader("Content-Type", "text/html; charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.end(html);
} catch {
next();
}
};
}
export default defineConfig({
plugins: [
{
name: "static-pages",
configureServer(server) {
server.middlewares.use(serveStaticPage(devStaticPageHtml));
},
configurePreviewServer(server) {
server.middlewares.use(serveStaticPage(previewStaticPageHtml));
},
},
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
staged: {
"*": "vp check --fix",
},
fmt: {
sortImports: {
groups: [
"type-import",
["value-builtin", "value-external"],
"type-internal",
"value-internal",
["type-parent", "type-sibling", "type-index"],
["value-parent", "value-sibling", "value-index"],
"unknown",
],
},
},
lint: {
ignorePatterns: ["node_modules/**", "coverage/**", "dist/**"],
plugins: ["react", "typescript", "unicorn", "oxc"],
categories: {
correctness: "error",
suspicious: "warn",
},
rules: {
"react/react-in-jsx-scope": "off",
},
env: {
browser: true,
node: true,
},
options: {},
},
});