forked from Voxelum/xmcl-page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
184 lines (164 loc) · 5.55 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { defineConfig } from 'vite'
import Layouts from 'vite-plugin-vue-layouts'
import Vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Markdown from 'vite-plugin-vue-markdown'
import WindiCSS from 'vite-plugin-windicss'
import VueI18n from '@intlify/unplugin-vue-i18n/vite'
import { resolve } from 'path'
import { VitePWA } from 'vite-plugin-pwa'
import generateSitemap from 'vite-ssg-sitemap'
// @ts-ignore
import LinkAttributes from 'markdown-it-link-attributes'
const markdownWrapperClasses = 'markdown-body'
export default defineConfig({
resolve: {
alias: {
'~/': `${resolve(__dirname, 'src')}/`,
},
},
plugins: [
Layouts({
extensions: ['vue', 'md'],
}),
{
name: 'latest-release',
resolveId(id) {
if (id === 'virtual:latest-release') {
return id
}
},
async load(id) {
if (id === 'virtual:latest-release') {
const resp = await fetch('https://api.github.com/repos/voxelum/x-minecraft-launcher/releases?per_page=5')
const releases = await resp.json().then(v => v instanceof Array ? v : [])
const filteredReleases = JSON.stringify((releases as any[]).map((r: any) => ({
assets: r.assets.map((a: any) => ({ name: a.name, browser_download_url: a.browser_download_url })),
prerelease: r.prerelease,
tag_name: r.tag_name
})))
return `export default ${filteredReleases}`
}
}
},
Vue({
include: [/\.vue$/, /\.md$/],
}),
// https://github.com/hannoeru/vite-plugin-pages
Pages({
extensions: ['vue', 'md'],
}),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
imports: [
'vue',
'vue-router',
'vue-i18n',
'@vueuse/head',
'@vueuse/core',
],
dts: 'src/auto-imports.d.ts',
}),
// https://github.com/antfu/unplugin-vue-components
Components({
// allow auto load markdown components under `./src/components/`
extensions: ['vue', 'md'],
// allow auto import and register components used in markdown
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
dirs: ['src/components'],
// // custom resolvers
// resolvers: [
// // auto import icons
// // https://github.com/antfu/unplugin-icons
// IconsResolver({
// componentPrefix: '',
// // enabledCollections: ['carbon']
// }),
// ],
dts: 'src/components.d.ts',
}),
// // https://github.com/antfu/unplugin-icons
// Icons({
// autoInstall: true,
// }),
// https://github.com/antfu/vite-plugin-windicss
WindiCSS({
safelist: [...markdownWrapperClasses, 'text-[rgb(61,239,233)]', 'text-[rgb(107,217,104)]', 'text-amber-600', 'text-emerald-700', 'text-red-700'],
}),
// https://github.com/antfu/vite-plugin-md
// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
Markdown({
wrapperClasses: markdownWrapperClasses,
markdownItOptions: {
html: true,
linkify: true,
typographer: true,
},
headEnabled: true,
}),
// https://github.com/antfu/vite-plugin-pwa
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.svg', 'robots.txt'],
workbox: {
globIgnores: ["**\/node_modules\/**\/*", "zh.html", "en.html", "ru.html", "index.html"],
globPatterns: ["**\/*.{js,css,html}"]
},
manifest: false,
}),
// https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
VueI18n({
runtimeOnly: true,
compositionOnly: true,
strictMessage: false,
fullInstall: true,
include: [resolve(__dirname, 'locales/**')],
}),
// https://github.com/antfu/vite-plugin-inspect
// Inspect({
// // change this to enable inspect for debugging
// enabled: false,
// }),
],
server: {
fs: {
strict: true,
},
},
// https://github.com/antfu/vite-ssg
ssgOptions: {
script: 'async',
formatting: 'minify',
onPageRendered(route, html, context) {
if (context.initialState.locale) {
html = html.replace(`lang="en"`, `lang="${context.initialState.locale}"`)
}
return html
},
onFinished() {
generateSitemap({
hostname: 'https://xmcl.app'
})
},
},
optimizeDeps: {
include: [
'vue',
'vue-router',
'@vueuse/core',
'@vueuse/head',
],
exclude: [
'vue-demi',
],
},
ssr: {
// TODO: workaround until they support native ESM
noExternal: [
'workbox-window',
/vue-i18n/,
],
},
})