2026-06-15 09:00:38 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2026-06-16 13:18:49 +08:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import path from 'path'
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
2026-06-15 09:00:38 +08:00
|
|
|
|
|
|
|
|
// https://vite.dev/config/
|
|
|
|
|
export default defineConfig({
|
2026-06-16 13:18:49 +08:00
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
|
|
|
|
// 让 Vite 开发服务器正确提供 .py 文件的静态服务
|
|
|
|
|
{
|
|
|
|
|
name: 'serve-py-files',
|
|
|
|
|
configureServer(server) {
|
|
|
|
|
server.middlewares.use((req, res, next) => {
|
|
|
|
|
const url = req.url
|
|
|
|
|
// 只处理 .py 文件请求,且排除 API 路径
|
|
|
|
|
if (url.endsWith('.py') && !url.startsWith('/api/')) {
|
|
|
|
|
const filePath = path.join(__dirname, 'public', url.replace(/^\//, ''))
|
|
|
|
|
if (fs.existsSync(filePath)) {
|
|
|
|
|
const content = fs.readFileSync(filePath, 'utf-8')
|
|
|
|
|
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
|
|
|
|
|
res.statusCode = 200
|
|
|
|
|
res.end(content)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
next()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
2026-06-15 10:59:56 +08:00
|
|
|
server: {
|
2026-06-16 09:19:33 +08:00
|
|
|
port: 1025,
|
2026-06-15 10:59:56 +08:00
|
|
|
proxy: {
|
|
|
|
|
'/api': {
|
2026-06-16 10:23:48 +08:00
|
|
|
target: 'http://localhost:3002',
|
2026-06-15 10:59:56 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-06-15 09:00:38 +08:00
|
|
|
test: {
|
|
|
|
|
environment: 'jsdom',
|
|
|
|
|
globals: true,
|
|
|
|
|
},
|
|
|
|
|
})
|