forked from misode/misode.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
44 lines (41 loc) · 1.14 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
import html from '@rollup/plugin-html'
import config from './src/config.json'
import { env } from 'process'
export default defineConfig({
build: {
sourcemap: true,
rollupOptions: {
plugins: [
html({
fileName: `404.html`,
title: '404',
template: template,
}),
...config.generators.map(m => html({
fileName: `${m.id}/index.html`,
title: getTitle(m),
template: template,
})),
],
},
},
json: {
stringify: true,
},
define: {
__MCDATA_MASTER_HASH__: env.mcdata_hash,
__VANILLA_DATAPACK_SUMMARY_HASH__: env.vanilla_datapack_summary_hash,
},
plugins: [preact()],
})
function getTitle(m) {
const minVersion = Math.max(0, config.versions.findIndex(v => m.minVersion === v.id))
const versions = config.versions.slice(minVersion).map(v => v.id).join(', ')
return `${m.name} Generator${m.category === true ? 's' : ''} Minecraft ${versions}`
}
function template({ files, title }) {
const source = files.html.find(f => f.fileName === 'index.html').source
return source.replace(/<title>.*<\/title>/, `<title>${title}</title>`)
}