diablo2-web/vite.config.ts

63 lines
1.5 KiB
TypeScript

import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
/**
* Vite configuration for the unified Diablo II web client (`play.html`).
*/
export default defineConfig({
plugins: [
{
name: 'd2web-sw-dev-alias',
configureServer(server) {
server.middlewares.use((req, _res, next) => {
if (req.url && /^\/(?:diablo2\/)?sw\.js(?:\?.*)?$/.test(req.url)) {
req.url = '/src/client/sw/sw.ts'
}
next()
})
},
},
{
name: 'd2-root-to-play-html',
configureServer(server) {
server.middlewares.use((req, _res, next) => {
if (req.url === '/' || req.url?.startsWith('/?')) {
req.url = `/play.html${req.url.slice(1)}`
}
next()
})
},
},
],
server: {
host: '127.0.0.1',
port: 5173,
strictPort: true,
proxy: {
'/d2net': {
target: 'wss://www.laiseek.xyz',
ws: true,
changeOrigin: true,
secure: true,
},
},
},
build: {
target: 'es2022',
sourcemap: true,
rollupOptions: {
input: {
play: resolve(__dirname, 'play.html'),
sw: resolve(__dirname, 'src/client/sw/sw.ts'),
},
output: {
entryFileNames: (chunkInfo) =>
chunkInfo.name === 'sw' ? 'sw.js' : 'assets/[name]-[hash].js',
},
},
},
})