Files
grok-icon-study/vite.config.ts
T
Edom 1ba126c92b feat:加上 Vue 学习站与可嵌入机芯
站点按 bloub 三栏做自定义、动画时间线和设置,支持序列导出。
形体只留常见几种并配中文名;动画页右栏拉满时间线旁空位,滚动条隐藏。
机芯补 GROK.create / <grok-bot>,以及暂停冻结。
2026-08-19 01:29:13 +08:00

45 lines
1.4 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'
}
return {
name: 'serve-replica',
configureServer(server) {
server.middlewares.use((req, res, next) => {
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))
})
}
}
}
export default defineConfig({
plugins: [vue(), tailwindcss(), serveReplica()],
server: { port: 5191 },
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }
}
})