|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import { basename, extname, resolve } from 'path'
|
|
|
|
|
|
|
|
const stripExt = path => basename(path, extname(path))
|
|
|
|
const entryPoints = ['index.html', 'login.html', 'user.html', 'game.html']
|
|
|
|
|
|
|
|
const redirect = redirectMap => ({
|
|
|
|
name: 'redirect',
|
|
|
|
configureServer(server) {
|
|
|
|
server.middlewares.use((req, res, next) => {
|
|
|
|
if (!!redirectMap[req.url]) {
|
|
|
|
res.statusCode = 302
|
|
|
|
res.setHeader('Location', redirectMap[req.url])
|
|
|
|
res.setHeader('Content-Length', '0')
|
|
|
|
res.end()
|
|
|
|
} else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const redirectMap = Object.fromEntries(entryPoints.map(path => ['/' + stripExt(path), '/' + path]))
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
build: {
|
|
|
|
rollupOptions: {
|
|
|
|
input: Object.fromEntries(
|
|
|
|
entryPoints.map(path => [stripExt(path), resolve(__dirname, path)])
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
proxy: {
|
|
|
|
'/api': 'http://127.0.0.1:4000',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: [redirect(redirectMap)],
|
|
|
|
})
|