acupedia-store-ui/vite.config.ts

33 lines
836 B
TypeScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
const rawBase = process.env.VITE_BASE_PATH || '/store/'
const baseWithoutSlash = rawBase.endsWith('/') ? rawBase.slice(0, -1) : rawBase
// https://vite.dev/config/
export default defineConfig({
base: rawBase,
plugins: [
react(),
{
name: 'redirect-base-middleware',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const [pathname, search] = (req.url || '').split('?')
if (baseWithoutSlash && pathname === baseWithoutSlash) {
const target = `${rawBase}${search ? `?${search}` : ''}`
res.writeHead(302, { Location: target })
res.end()
return
}
next()
})
}
}
],
server: {
port: 3000,
}
})