feat(Compare): 增加延迟对比功能
This commit is contained in:
@@ -1,15 +1,65 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, type PluginOption } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
// SPA fallback middleware - runs after Vite's built-in middleware
|
||||
function spaFallback(): PluginOption {
|
||||
return {
|
||||
name: 'spa-fallback',
|
||||
configureServer(server) {
|
||||
// Return a function to execute after Vite's internal middleware
|
||||
return () => {
|
||||
server.middlewares.use((req, res, next) => {
|
||||
// Skip API routes and file requests
|
||||
if (req.url?.startsWith('/api') || req.url?.includes('.')) {
|
||||
return next()
|
||||
}
|
||||
|
||||
// Serve index.html for SPA routes
|
||||
const indexPath = path.resolve(__dirname, 'index.html')
|
||||
if (fs.existsSync(indexPath)) {
|
||||
res.statusCode = 200
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
let html = fs.readFileSync(indexPath, 'utf-8')
|
||||
server.transformIndexHtml(req.url || '/', html).then(transformed => {
|
||||
res.end(transformed)
|
||||
}).catch(next)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
configurePreviewServer(server) {
|
||||
// Same logic for preview server
|
||||
server.middlewares.use((req, res, next) => {
|
||||
if (req.url?.startsWith('/api') || req.url?.includes('.')) {
|
||||
return next()
|
||||
}
|
||||
|
||||
const indexPath = path.resolve(__dirname, 'dist/client/index.html')
|
||||
if (fs.existsSync(indexPath)) {
|
||||
res.statusCode = 200
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.end(fs.readFileSync(indexPath, 'utf-8'))
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
plugins: [react(), spaFallback()],
|
||||
root: '.',
|
||||
publicDir: 'public',
|
||||
build: {
|
||||
outDir: 'dist/client',
|
||||
},
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:3000',
|
||||
@@ -17,6 +67,9 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
host: '0.0.0.0',
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, 'src/client'),
|
||||
|
||||
Reference in New Issue
Block a user