-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
83 lines (78 loc) · 3.6 KB
/
Copy pathvite.config.ts
File metadata and controls
83 lines (78 loc) · 3.6 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
import tailwindcss from "@tailwindcss/vite";
// @ts-expect-error — 로컬 스크립트 (타입 선언 없음)
import { kbLocPlugin } from "./scripts/kb-loc-vite.mjs";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import viteReact from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import tsConfigPaths from "vite-tsconfig-paths";
import { readFileSync } from "node:fs";
interface PrerenderManifest {
static?: string[];
concrete?: string[];
}
function prerenderManifest(): PrerenderManifest {
try {
return JSON.parse(readFileSync("public/prerender-routes.json", "utf8")) as PrerenderManifest;
} catch {
return {};
}
}
const manifest = prerenderManifest();
function canonicalPrerenderPath(path: string): string {
return path.replace(/\/+$/, "") || "/";
}
// File routes representing an index page use a trailing slash (for example `/products/`),
// while TanStack's crawler reports the same page without it. Compare canonical forms so an
// explicitly public index route is not silently filtered out of the static deployment.
const allowedPrerenderPaths = new Set(
[...(manifest.static ?? []), ...(manifest.concrete ?? [])].map(canonicalPrerenderPath),
);
export default defineConfig({
// 프리렌더는 vite preview(port 0)를 띄워 127.0.0.1로 fetch한다. 샌드박스(알파인)에서는
// localhost가 ::1로 먼저 해석돼 v6에만 바인딩되고 fetch가 전멸하므로 v4를 명시한다.
preview: { host: "127.0.0.1" },
/**
* 커넥터 SDK 를 SSR 번들에도 **포함**시킨다.
*
* 기본값(외부화)이면 SSR/프리렌더에서는 커넥터가 변환되지 않아 `import.meta.env.VITE_*` 가
* 치환되지 않는다. 그래서 `CONNECTED = Boolean(VITE_KB_CONNECTOR_URL && ..._KEY)` 가
* 서버에서는 false, 브라우저에서는 true 가 되어 **조건부 문구가 서로 달라지고**
* React 하이드레이션 불일치(#418)가 난다 — 2026-07-27 실측에서 261종 중 138종이 여기 걸렸다.
*/
ssr: { noExternal: [/^@k-builder\//] },
build: {
rollupOptions: {
output: {
// TanStack Start performs independent client and SSR builds. A content-hashed
// `?url` CSS import can therefore receive two different hashes, leaving the
// prerendered HTML pointing at the SSR-only name. Keep the single application
// stylesheet address stable across both builds; all other assets remain hashed.
assetFileNames(asset) {
const names = asset.names.length > 0 ? asset.names : [asset.name ?? ""];
return names.some((name) => name.endsWith(".css"))
? "assets/app.css"
: "assets/[name]-[hash][extname]";
},
},
},
},
plugins: [
// Visual Edits (KB-W1-06): 다른 변환보다 **먼저** 원본 소스에 data-kb-loc 좌표를 심는다.
// TanStack Start의 라우트 분할 뒤에 심으면 줄 번호가 어긋난다(실측).
kbLocPlugin(),
tsConfigPaths(),
tailwindcss(),
// prerender: 루트에서 링크를 크롤링해 라우트별 정적 HTML 생성 — KB-W0-06 콜드 프리뷰와
// KB-W0-07 정적 배포 경로의 산출물 (SSR 서버 번들은 별도 생성, 런타임은 W1-23)
tanstackStart({
pages: (manifest.concrete ?? []).map((path) => ({ path })),
prerender: {
enabled: true,
crawlLinks: true,
// 크롤러가 공개 페이지의 /admin 링크를 따라가 운영 화면까지 정적 배포하던 문제를 차단한다.
filter: (page) => allowedPrerenderPaths.has(canonicalPrerenderPath(page.path)),
},
}),
viteReact(),
],
});