|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import { resolve } from 'path'
|
|
|
|
|
|
|
|
import preact from '@preact/preset-vite'
|
|
|
|
|
|
|
|
const entryPoints = ['index', 'login', 'register', 'user', 'game', 'crea-partita']
|
|
|
|
|
|
|
|
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(page => ['/' + page, '/' + page + '.html']))
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
build: {
|
|
|
|
rollupOptions: {
|
|
|
|
input: Object.fromEntries(
|
|
|
|
entryPoints.map(page => [page, resolve(__dirname, page + '.html')])
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
proxy: {
|
|
|
|
'/api': 'http://127.0.0.1:4000',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: [preact(), redirect(redirectMap)],
|
|
|
|
})
|