-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
41 lines (40 loc) · 1.43 KB
/
Copy pathvite.config.ts
File metadata and controls
41 lines (40 loc) · 1.43 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
import { existsSync, renameSync, rmSync } from "node:fs"
import path from "node:path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
// Pulls in the `ssgOptions` augmentation on Vite's UserConfig.
import type {} from "vite-react-ssg"
export default defineConfig({
base: "/",
publicDir: path.resolve(__dirname, "public"),
plugins: [react(), tailwindcss()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
build: {
outDir: path.resolve(__dirname, "dist"),
emptyOutDir: true,
},
ssgOptions: {
// /foo -> dist/foo/index.html (deep links served directly by GitHub Pages)
dirStyle: "nested",
// Render the catch-all route at a concrete /404 path so the NotFound page
// is prerendered. The splat ("*") itself is dynamic and dropped by the
// built-in filter, so without this there'd be no 404 page at all.
includedRoutes: (paths) => [...paths, "/404"],
// GitHub Pages serves /404.html for unmatched URLs. Promote the
// prerendered dist/404/index.html to dist/404.html.
onFinished: () => {
const dist = path.resolve(__dirname, "dist")
const nested = path.join(dist, "404", "index.html")
const flat = path.join(dist, "404.html")
if (existsSync(nested)) {
renameSync(nested, flat)
rmSync(path.join(dist, "404"), { recursive: true, force: true })
}
},
},
})