Files
music_quiz/apps/web/vite.config.ts

37 lines
1.2 KiB
TypeScript

import { createHash } from 'node:crypto';
import { defineConfig, type Plugin } from 'vite';
import react from '@vitejs/plugin-react';
/**
* Writes `<meta name="mq-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 (업데이트 알림, same as joke-app).
*/
function buildId(): Plugin {
return {
name: 'mq-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: 'mq-build', content: build }, injectTo: 'head' }];
},
},
};
}
export default defineConfig({
plugins: [react(), buildId()],
server: {
port: 5173,
proxy: {
'/api': 'http://localhost:3000',
'/healthz': 'http://localhost:3000',
'/ws': { target: 'ws://localhost:3000', ws: true },
},
},
build: { target: 'es2022', sourcemap: false },
});