-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
vite.config.js
94 lines (90 loc) · 2.84 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import preact from '@preact/preset-vite'
import html from '@rollup/plugin-html'
import { env } from 'process'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'
const config = require('./src/config.json')
const English = require('./src/locales/en.json')
const convertFormats = ['give-command', 'loot-table', 'item-modifier', 'recipe-output']
export default defineConfig({
server: {
port: 3000,
},
resolve: {
alias: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom/test-utils', replacement: 'preact/test-utils' },
{ find: 'react-dom', replacement: 'preact/compat' },
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' },
],
},
optimizeDeps: {
esbuildOptions: {
target: 'es2021',
},
},
build: {
sourcemap: true,
target: 'es2021',
rollupOptions: {
plugins: [
html({
fileName: '404.html',
title: '404',
template,
}),
...['generators', 'worldgen', 'partners', 'sounds', 'changelog', 'versions', 'guides', 'transformation', 'customized'].map(id => html({
fileName: `${id}/index.html`,
title: `${English[`title.${id}`] ?? ''} - ${getVersions()}`,
template,
})),
...config.generators.map(m => html({
fileName: `${m.url}/index.html`,
title: `${English[m.id] ?? ''} Generator${m.category === true ? 's' : ''} - ${getVersions(m)}`,
template,
})),
...convertFormats.flatMap(s => convertFormats.filter(t => s !== t).map(t => [s, t])).map(([s, t]) => html({
fileName: `convert/${s}-to-${t}/index.html`,
title: `${English[`convert.format.${s}`]} to ${English[`convert.format.${t}`]} Converter - ${getVersions({ minVersion: '1.20.5' })}`,
template,
})),
...config.legacyGuides.map(g => html({
fileName: `guides/${g.id}/index.html`,
title: `${g.title} - ${getVersions()}`,
template,
})),
],
},
},
json: {
stringify: true,
},
define: {
__LATEST_VERSION__: env.latest_version,
},
plugins: [
preact(),
viteStaticCopy({
targets: [
{ src: 'src/styles/giscus.css', dest: 'assets' },
{ src: 'src/styles/giscus-burn.css', dest: 'assets' },
],
}),
visualizer({ open: true }),
],
})
function getVersions(m) {
const minVersion = Math.max(0, config.versions.findIndex(v => m?.minVersion === v.id))
const maxVersion = config.versions.findIndex(v => m?.maxVersion === v.id)
const versions = config.versions
.filter((_, i) => minVersion <= i && (maxVersion === -1 || i <= maxVersion))
.map(v => v.id)
.filter((v, _, arr) => v.length === 4 || arr.length <= 3)
.slice(-3)
return `Minecraft ${versions.join(', ')}`
}
function template({ files, title }) {
const source = files.html.find(f => f.fileName === 'index.html').source
return source.replace(/<title>.*<\/title>/, `<title>${title}</title>`)
}