-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
96 lines (91 loc) · 2.51 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
import { fileURLToPath, URL } from 'node:url'
import Shiki from '@shikijs/markdown-it'
import Vue from '@vitejs/plugin-vue'
import container from 'markdown-it-container'
import LinkAttributes from 'markdown-it-link-attributes'
import UnpluginDetectDuplicatedDeps from 'unplugin-detect-duplicated-deps/vite'
import Markdown from 'unplugin-vue-markdown/vite'
import { defineConfig, type Plugin } from 'vite'
// @ts-expect-error any
import leetcode from './blogs/algorithm/leetcode'
import injectBuildInfo from './scripts/build-info'
import mdDetail from './scripts/markdown-detail'
import preRender from './scripts/prerender'
import getPWAConfig from './scripts/pwa-plugin'
// https://vitejs.dev/config/
export default defineConfig((environment) => ({
resolve: {
alias: {
'@': fileURLToPath(new URL('src', import.meta.url))
}
},
build: {
copyPublicDir: !environment.isSsrBuild,
minify: !environment.isSsrBuild,
rollupOptions: {
// input: {
// index: fileURLToPath(new URL('index.html', import.meta.url))
// },
output: {
manualChunks(id) {
if (environment.isSsrBuild) {
return
}
if (id.includes('/node_modules/') && !id.endsWith('.css')) {
return 'vendor'
}
}
}
}
},
plugins: [
// splitVendorChunkPlugin(),
UnpluginDetectDuplicatedDeps({ throwErrorWhenDuplicated: true }),
Vue({
include: [/\.vue$/, /\.md$/], // <--
template: {
compilerOptions: {
isCustomElement: (tag) => {
return ['iconify-icon'].includes(tag)
}
}
}
}),
getPWAConfig(!!environment.isSsrBuild),
Markdown({
wrapperClasses: 'markdown-body',
async markdownItSetup(md) {
md.use(container, 'detail', mdDetail)
md.use(
await Shiki({
themes: {
light: 'github-light',
dark: 'github-dark'
}
})
)
md.use(LinkAttributes, {
matcher: (link: string) => /^https?:\/\//.test(link),
attrs: {
target: '_blank',
rel: 'noopener'
}
})
}
}),
injectBuildInfo(),
preRender({
routes: ['/', '/404', '/blog', '/music', '/movie'],
ssrEntry: 'server.js'
}),
{
name: 'leetcode-generator-plugin',
enforce: 'pre',
load(id) {
if (id.endsWith('/leetcode题目汇总.md')) {
return leetcode
}
}
} satisfies Plugin
]
}))