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.
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import { defineConfig } from 'vite'
|
|
import { resolve } from 'path'
|
|
|
|
import preact from '@preact/preset-vite'
|
|
|
|
const entryPoints = ['index', 'login', 'register', 'profile', 'partita', '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': {
|
|
target: 'http://127.0.0.1:4000',
|
|
changeOrigin: true,
|
|
rewrite: path => path,
|
|
},
|
|
},
|
|
},
|
|
plugins: [
|
|
preact(),
|
|
redirect(redirectMap),
|
|
{
|
|
name: 'boh',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
if (req.url.startsWith('/p/')) {
|
|
req.url = '/partita.html'
|
|
}
|
|
|
|
next()
|
|
})
|
|
},
|
|
},
|
|
],
|
|
})
|