-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
77 lines (71 loc) · 1.84 KB
/
vite.config.ts
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
import { defineConfig } from 'vite'
import { readdirSync, readFileSync } from 'fs'
import { join } from 'path'
import Vue from '@vitejs/plugin-vue'
import Components from 'vite-plugin-components'
import ViteIcons, { ViteIconsResolver } from 'vite-plugin-icons'
import dotenv from 'dotenv'
const { parsed } = dotenv.config()
const renderRoutes = parsed?.VITE_LANDING_ONLY === 'yes'
? (() => {
const routes = [
'/',
'/landing',
'/session'
].flatMap(r => [r, `${r}/`])
return Array.from(readdirSync('./locales/'))
.flatMap((locale) => {
return routes
.map((route) => join('/', locale, route))
.concat(join('/', locale, '/session/template'))
})
})()
: (() => {
const routes = [
'/',
'/landing',
'/session',
'/room',
'/venue',
'/map',
'/sponsor',
'/staff'
].flatMap(r => [r, `${r}/`])
return Array.from(readdirSync('./locales/'))
.flatMap((locale) => {
return routes
.map((route) => join('/', locale, route))
.concat(join('/', locale, '/session/template'))
})
})()
const gaTemplate = readFileSync(join(__dirname, './templates/ga-template.html')).toString()
export default defineConfig({
base: parsed?.VITE_BASE_URL,
resolve: {
alias: {
'@': `${join(__dirname, 'src')}`
}
},
plugins: [
Vue({
include: [/\.vue$/, /\.md$/]
}),
Components({
customComponentResolvers: ViteIconsResolver({
componentPrefix: 'icon'
})
}),
ViteIcons()
],
ssgOptions: {
script: 'async',
formatting: 'minify',
includedRoutes () {
return renderRoutes
},
onPageRendered: (r, html) => {
return html
.replace('<template>%GA_TEMPLATE%</template>', gaTemplate)
}
}
})