- 난이도 1~60(쉬움 1~20·보통 21~40·어려움 41~60): 넣을 때 랜덤, 방장이 대기실에서 [랜덤][쉬움][보통][어려움] 선택(botLevel) → 범위 안 무작위 - 다음 판마다 -2~+2, 처음 단계 ±5·같은 범위 안(drift); 말투는 처음 단계(>30 존댓말) - humanBest 확률을 단계별로 보간(BOT_PLAY_ANCHORS: 1·10·30·50·60) - 운(-1~+1): 카드·주사위 게임에서 시작 전에 시드 후보 1~5개를 작업 스레드에서 끝까지 둬 보고 운에 맞는 것을 고름(luck.ts, luck-worker.ts). 해시 공개는 그대로 - 결과 화면 공정성 확인에 컴퓨터별 단계·운, 섞어 본 후보 수 - 업데이트 알림: 빌드 ID meta + /api/version + welcome.build → 상단 팝업 [지금 새로고침하기] [✕] - 문서 03·04 §5.1·06 §12·07 §11.1·09 §9.1, 테스트(bot-level.room, luck, version, e2e bots·pwa) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
import { createHash } from 'node:crypto';
|
|
import { readFileSync } from 'node:fs';
|
|
import { defineConfig, type Plugin } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
/** Emits dist/sw.js with a build id, so a deploy that changes files installs a new worker (docs/07 §11). */
|
|
function serviceWorker(): Plugin {
|
|
return {
|
|
name: 'bg-service-worker',
|
|
apply: 'build',
|
|
generateBundle(_, bundle) {
|
|
const src = readFileSync(new URL('./sw.js', import.meta.url), 'utf8');
|
|
const offline = readFileSync(new URL('./public/offline.html', import.meta.url), 'utf8');
|
|
const files = Object.keys(bundle).sort().join('\n');
|
|
const build = createHash('sha256').update(src).update(offline).update(files).digest('hex').slice(0, 12);
|
|
if (!src.includes("'__BUILD__'")) throw new Error('sw.js: VERSION placeholder missing');
|
|
this.emitFile({ type: 'asset', fileName: 'sw.js', source: src.replace("'__BUILD__'", `'${build}'`) });
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Writes `<meta name="bg-build" content="…">` into index.html: a hash of the built file names, so it changes whenever
|
|
* any script or style changes. The server reads it from dist/index.html; an open page compares its own with the
|
|
* server's and offers to refresh (docs/07 §11.1).
|
|
*/
|
|
function buildId(): Plugin {
|
|
return {
|
|
name: 'bg-build-id',
|
|
apply: 'build',
|
|
transformIndexHtml: {
|
|
order: 'post',
|
|
handler(html, ctx) {
|
|
const files = Object.keys(ctx.bundle ?? {}).filter((f) => !f.endsWith('.html')).sort().join('\n');
|
|
const build = createHash('sha256').update(files).digest('hex').slice(0, 12);
|
|
return [{ tag: 'meta', attrs: { name: 'bg-build', content: build }, injectTo: 'head' }];
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [react(), serviceWorker(), buildId()],
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
'/api': 'http://localhost:3000',
|
|
'/healthz': 'http://localhost:3000',
|
|
'/ws': { target: 'ws://localhost:3000', ws: true },
|
|
},
|
|
},
|
|
build: {
|
|
target: 'es2022',
|
|
cssCodeSplit: true,
|
|
sourcemap: false,
|
|
},
|
|
});
|