Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
60 lines (59 loc) · 2.4 KB
/
Copy pathvite.config.ts
File metadata and controls
60 lines (59 loc) · 2.4 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
import { resolve } from "node:path";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
{
// GitHub Pages serves /privacy-policy from privacy-policy.html; teach
// the dev server the same trick so the footer links work locally.
name: "clean-urls",
configureServer(server) {
server.middlewares.use((req, _res, next) => {
const clean = req.url?.replace(/[?#].*$/, "");
if (
clean === "/privacy-policy" ||
clean === "/terms-of-service" ||
clean === "/fact-sheet" ||
clean === "/zh/fact-sheet" ||
clean === "/ja/fact-sheet"
) {
req.url = `${clean}.html${req.url!.slice(clean.length)}`;
} else if (clean === "/en/fact-sheet") {
// The build writes a copy of the English page here; in dev, alias it.
req.url = `/fact-sheet.html${req.url!.slice(clean.length)}`;
} else if (clean === "/en/") {
req.url = `/index.html${req.url!.slice(clean.length)}`;
}
next();
});
},
},
],
build: {
// Real HTML entries, one per page. The legal pages are root-level .html files
// rather than directories, because GitHub Pages serves /privacy-policy
// from privacy-policy.html directly — a 200 on the exact slashless URL
// handed to Google's OAuth review, with no redirect in the way.
rollupOptions: {
input: {
index: resolve(import.meta.dirname, "index.html"),
"zh/index": resolve(import.meta.dirname, "zh/index.html"),
"ja/index": resolve(import.meta.dirname, "ja/index.html"),
"privacy-policy": resolve(import.meta.dirname, "privacy-policy.html"),
"terms-of-service": resolve(import.meta.dirname, "terms-of-service.html"),
"fact-sheet": resolve(import.meta.dirname, "fact-sheet.html"),
// Language versions live under a prefix: /zh/fact-sheet.
"zh/fact-sheet": resolve(import.meta.dirname, "zh/fact-sheet.html"),
"ja/fact-sheet": resolve(import.meta.dirname, "ja/fact-sheet.html"),
},
},
},
server: {
// Honour the port the launcher hands us, so a stray process on 5173
// doesn't quietly steal the preview.
port: Number(process.env.PORT) || 5173,
strictPort: Boolean(process.env.PORT),
},
})