Files
grok-icon-study/vite.config.ts
T
Edom 851f2b8c6c fix:修导出时钟与切页卡顿
导出与播放共用模拟时钟;换循环、重排播放头、<grok-bot> 重挂和构建产物对齐。
自定义/动画面板留下不重画,角色高度对齐,表情走弹簧。
2026-08-19 02:01:29 +08:00

58 lines
1.7 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath, URL } from 'node:url'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig, type Plugin } from 'vite'
function serveReplica(): Plugin {
const root = fileURLToPath(new URL('./replica', import.meta.url))
const types: Record<string, string> = {
'.html': 'text/html; charset=utf-8',
'.js': 'application/javascript; charset=utf-8',
'.svg': 'image/svg+xml',
'.md': 'text/markdown; charset=utf-8'
}
function middleware(
req: { url?: string },
res: { statusCode: number; setHeader: (k: string, v: string) => void; end: (b?: Buffer) => void },
next: () => void
) {
if (!req.url?.startsWith('/replica/')) {
next()
return
}
const rel = decodeURIComponent(req.url.slice('/replica/'.length).split('?')[0] || '')
const file = path.resolve(root, rel)
if (!file.startsWith(root) || !fs.existsSync(file) || fs.statSync(file).isDirectory()) {
res.statusCode = 404
res.end()
return
}
res.setHeader('Content-Type', types[path.extname(file)] || 'application/octet-stream')
res.end(fs.readFileSync(file))
}
return {
name: 'serve-replica',
configureServer(server) {
server.middlewares.use(middleware)
},
configurePreviewServer(server) {
server.middlewares.use(middleware)
},
writeBundle(options) {
const dest = path.resolve(options.dir ?? 'dist', 'replica')
fs.cpSync(root, dest, { recursive: true })
}
}
}
export default defineConfig({
plugins: [vue(), tailwindcss(), serveReplica()],
server: { port: 5191 },
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }
}
})