o2o-site-AEO/solution/site/vite.config.ts
Mina Choi f2087aad5e feat(solution): 발행 워커·버전 관리와 예약·미리보기 정리
상시 프리렌더와 중복 예약 안내를 없애고, 검수된 발행 버전을 보존한다. 미리보기는 실제 렌더 완료까지 스피너를 표시한다.

사이트 81건, 발행·롤백·서치콘솔 45건, 프로세스 수명 3건 통과. 빌더·사이트 빌드 및 compose 설정 검증 통과.
2026-09-15 16:12:16 +09:00

49 lines
2.3 KiB
TypeScript

import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import {defineConfig} from 'vite';
/**
* 발행 사이트 렌더러.
*
* 빌드가 두 번 돈다:
* build:client → dist/client 브라우저 번들 + manifest(자산 경로를 프리렌더가 읽는다)
* build:prerender → dist/prerender 프리렌더러 자체를 SSR 번들로 묶는다
* (별도 TS 로더 없이 경로 별칭·TSX·CSS import 가 해결된다)
* 그다음 node dist/prerender/prerender.js 가 payload 마다 정적 HTML 을 굽는다.
*
* ★ 이 앱은 런타임 서버가 없다. 결과물은 파일뿐이라 어디에 올려도 돈다.
*/
export default defineConfig(({isSsrBuild}) => ({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
// ★ 별칭이 '@' 가 아니라 '@site' 인 이유(2026-09-09)
// 빌더 미리보기가 **이 렌더러를 그대로** 쓴다(solution/frontend). 두 앱이 '@' 를
// 각자 자기 src 로 두면, 여기 컴포넌트를 저쪽에서 불러올 때 내부 import 가
// 저쪽 src 로 떨어져 조용히 다른 파일을 잡는다. 이름을 갈라 두면 어디서 불러도 같다.
'@site': path.resolve(__dirname, 'src'),
'@o2o/shared': path.resolve(__dirname, '../shared/src'),
},
},
build: {
// 프리렌더가 산출물 파일명을 알아야 HTML 에 <script src> 를 박을 수 있다.
manifest: !isSsrBuild,
emptyOutDir: true,
rollupOptions: isSsrBuild
? undefined // --ssr 로 넘긴 엔트리를 그대로 쓴다.
: {input: path.resolve(__dirname, 'index.html')},
},
// ★ SSR 번들(dist/prerender/prerender.js)에 react·react-dom 등 node_modules 의존성까지
// 전부 접어 넣는다. 워커 이미지가 "Node 런타임 + 컴파일된 렌더러"만 담게 하려는 것이다
// (컨테이너 안에서 npm install 을 돌리지 않는다). noExternal 없이는 이 번들이 실행 시점에
// node_modules 를 다시 찾는다 — 실측: node_modules 를 지우고 돌리면
// `Cannot find package 'clsx'` 로 즉시 죽는다.
ssr: {
noExternal: true,
},
server: {
watch: {usePolling: true, interval: 300},
},
}));