-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
85 lines (78 loc) · 3.05 KB
/
vite.config.ts
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
import prerender from "@prerenderer/rollup-plugin";
import chromium from "@sparticuz/chromium-min";
import react from "@vitejs/plugin-react-swc";
import { defineConfig, loadEnv } from "vite";
import svgr from "vite-plugin-svgr";
import tsconfigPaths from "vite-tsconfig-paths";
import { generatePerformanceRoutes } from "./src/utils/generatePerformanceRoute";
import axios from "axios";
// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const routes = await generatePerformanceRoutes(env.VITE_API_BASE_URL);
const executablePath =
env.VITE_CHROME_PATH ||
(await chromium.executablePath(
"https://github.com/Sparticuz/chromium/releases/download/v121.0.0/chromium-v121.0.0-pack.tar"
));
return {
plugins: [
react(),
prerender({
routes,
renderer: "@prerenderer/renderer-puppeteer",
rendererOptions: {
launchOptions: {
args: ["--no-sandbox", "--disable-setuid-sandbox"],
ignoreDefaultArgs: ["--disable-extensions"],
defaultViewport: chromium.defaultViewport,
executablePath,
ignoreHTTPSErrors: true,
headless: chromium.headless,
},
maxConcurrentRoutes: 1,
renderAfterTime: 500,
customPuppeteerModule: "puppeteer-core",
},
// Debugging
postProcess: async (context) => {
console.log(`Prerendered: ${context.route}`);
if (context.route.includes("/gig")) {
const response = await axios.get(
`${env.VITE_API_BASE_URL}/performances/detail/${context.route.slice(context.route.lastIndexOf("/") + 1)}`
);
const performanceData = response.data.data;
context.html = context.html
.replace(/<meta property="og:title".*?>/i, "")
.replace(/<meta property="og:image".*?>/i, "")
.replace(/<meta property="og:description".*?>/i, "")
.replace(/<meta property="og:url".*?>/i, "");
context.html = context.html.replace(
/<\/head>/i,
`
<meta property="og:title" content="${performanceData.performanceTitle || "BEAT"}" />
<meta property="og:image" content="${performanceData.posterImage || "https://www.sinjibabo.shop/og_img.png"}" />
<meta name="keywords" content="공연, 밴드, 뮤지컬, 비트, beat" />
<meta property="og:description" content="${performanceData.performanceDescription || "심장이 뛰는 곳, BEAT에서 만나보세요."}" />
<meta property="og:url" content="${env.VITE_CLIENT_URL}/gig/${performanceData.performanceId}" />
</head>`
);
}
},
}),
svgr({
svgrOptions: {
icon: true,
memo: true,
},
}),
tsconfigPaths(),
],
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
optimizeDeps: {
include: ["react-lottie-player"],
},
};
});