You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
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)],
|
|
})
|