-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
84 lines (76 loc) · 2.52 KB
/
Copy pathvite.config.ts
File metadata and controls
84 lines (76 loc) · 2.52 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
import { spawn } from "node:child_process"
import fs from "node:fs"
import path from "node:path"
import react from "@vitejs/plugin-react"
import type { Plugin } from "vite"
import { defineConfig, loadEnv } from "vite"
import { inspectAttr } from 'kimi-plugin-inspect-react'
import { BLOG_POSTS } from "./src/data/blogPosts"
import { PORTFOLIO_POSTS } from "./src/data/portfolioPosts"
function seoSitemapPlugin(): Plugin {
return {
name: "seo-sitemap-robots",
apply: "build",
writeBundle(options) {
const outDir = options.dir ?? "dist"
const env = loadEnv("production", process.cwd(), "")
const siteUrl = (env.VITE_SITE_URL || "https://777wrapping.com").replace(/\/$/, "")
const lastmod = new Date().toISOString().split("T")[0] ?? ""
const paths: string[] = ["/", "/portfolio", "/blog", "/about", "/privacy", "/terms"]
for (const p of PORTFOLIO_POSTS) paths.push(`/portfolio/${p.id}`)
for (const p of BLOG_POSTS) paths.push(`/blog/${p.slug}`)
const urlEntries = paths
.map(
(locPath) => ` <url>
<loc>${siteUrl}${locPath}</loc>
<lastmod>${lastmod}</lastmod>
</url>`
)
.join("\n")
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urlEntries}
</urlset>
`
fs.writeFileSync(path.join(outDir, "sitemap.xml"), sitemap, "utf8")
const robots = `User-agent: *
Allow: /
Sitemap: ${siteUrl}/sitemap.xml
`
fs.writeFileSync(path.join(outDir, "robots.txt"), robots, "utf8")
},
}
}
/** After each production build (watch), upload dist/ via scripts/deploy-sftp.mjs when DEPLOY_LIVE=1 */
function liveDeployPlugin(): Plugin {
return {
name: "live-deploy-sftp",
apply: "build",
closeBundle() {
if (process.env.DEPLOY_LIVE !== "1") return
const script = path.join(__dirname, "scripts", "deploy-sftp.mjs")
const child = spawn(process.execPath, [script], {
cwd: __dirname,
stdio: "inherit",
})
child.on("exit", (code) => {
if (code !== 0) console.error("[live-deploy] deploy exited with", code)
})
},
}
}
// https://vite.dev/config/
export default defineConfig({
/** Root `/` so assets (logo, /blog/*, /portfolio/*) resolve correctly on nested routes like /blog/slug */
base: '/',
server: {
port: 3000,
strictPort: false,
},
plugins: [inspectAttr(), react(), seoSitemapPlugin(), liveDeployPlugin()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});