diablo2-web/vite.config.ts

57 lines
1.8 KiB
TypeScript

import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
/**
* The engine is plain TypeScript with no runtime dependencies: Vite only serves
* and bundles it. Two entries: the real campaign scene (`acts.html`) and the
* combat math arena (`arena.html`). `samples/` is served in dev so all of them can
* be smoke-tested over HTTP (`?sample=samples/spawn.mpq`,
* `?data=samples/fixtures`).
*/
export default defineConfig({
server: {
host: '127.0.0.1',
port: 5173,
strictPort: true,
},
plugins: [
{
name: 'root-redirect',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url === '/' || req.url === '/index.html') {
res.writeHead(302, { Location: '/acts.html' })
res.end()
return
}
next()
})
},
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'index.html',
source:
'<!doctype html><html lang="zh-CN"><head><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=./acts.html"><title>d2web</title><script>location.replace("./acts.html" + location.search + location.hash)</script></head><body><a href="./acts.html">跳转至暗黑破坏神 2 游戏主界面</a></body></html>\n',
})
},
},
],
build: {
target: 'es2022',
sourcemap: true,
rollupOptions: {
input: {
acts: new URL('./acts.html', import.meta.url).pathname,
arena: new URL('./arena.html', import.meta.url).pathname,
loot: resolve(__dirname, 'loot.html'),
boss: resolve(__dirname, 'boss.html'),
skills: resolve(__dirname, 'skills.html'),
},
},
},
})