-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
133 lines (123 loc) · 3.93 KB
/
vite.config.ts
File metadata and controls
133 lines (123 loc) · 3.93 KB
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
import { fileURLToPath, URL } from 'node:url'
import { fromHighlighter } from '@shikijs/markdown-it/core'
import { createHighlighterCore } from 'shiki/core'
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
import UnocssVitePlugin from 'unocss/vite'
import Components from 'unplugin-vue-components/vite'
import Markdown from 'unplugin-vue-markdown/vite'
import Vue from 'unplugin-vue/rolldown'
import { defineConfig } from 'vite'
import Layouts from 'vite-plugin-vue-layouts-next'
import VueRouter from 'vue-router/vite'
// Types
import type { BundledLanguage, BundledTheme, HighlighterGeneric } from 'shiki'
const SHIKI_THEMES = {
light: 'github-light-default',
dark: 'github-dark-default',
} as const
async function createMarkdownPlugin () {
const highlighter = await createHighlighterCore({
themes: [
import('@shikijs/themes/github-light-default'),
import('@shikijs/themes/github-dark-default'),
],
langs: [
import('@shikijs/langs/typescript'),
import('@shikijs/langs/vue'),
import('@shikijs/langs/bash'),
],
engine: createJavaScriptRegexEngine(),
})
return Markdown({
wrapperClasses: '',
markdownItSetup (md) {
md.use(
fromHighlighter(highlighter as HighlighterGeneric<BundledLanguage, BundledTheme>, {
themes: SHIKI_THEMES,
defaultColor: false,
}),
)
// Wrap tables in scrollable container
md.renderer.rules.table_open = () => '<div class="overflow-x-auto mb-4"><table>'
md.renderer.rules.table_close = () => '</table></div>'
// Open external links in new window with ↗ suffix
const defaultLinkClose = md.renderer.rules.link_close
md.renderer.rules.link_open = (tokens, index, options, _env, self) => {
const token = tokens[index]
const href = token.attrGet('href') || ''
if (/^https?:\/\//i.test(href)) {
token.attrSet('target', '_blank')
token.attrSet('rel', 'noopener noreferrer')
token.attrSet('data-external', '')
}
return self.renderToken(tokens, index, options)
}
md.renderer.rules.link_close = (tokens, index, options, env, self) => {
for (let i = index - 1; i >= 0; i--) {
const open = tokens[i]
if (open.type === 'link_open' && open.attrGet('data-external') !== null) {
const close = defaultLinkClose
? defaultLinkClose(tokens, index, options, env, self)
: self.renderToken(tokens, index, options)
return '↗' + close
}
if (open.type === 'link_open') break
}
return defaultLinkClose
? defaultLinkClose(tokens, index, options, env, self)
: self.renderToken(tokens, index, options)
}
},
})
}
export default defineConfig({
optimizeDeps: {
exclude: ['@vue/repl'],
},
ssr: {
noExternal: ['@vue/repl'],
},
build: {
sourcemap: true,
},
css: {
transformer: 'postcss',
},
plugins: [
VueRouter({
dts: './src/typed-router.d.ts',
extensions: ['.vue', '.md'],
}),
Vue({
include: [/\.vue$/, /\.md$/],
}),
await createMarkdownPlugin(),
Components({
dirs: ['src/components'],
extensions: ['vue'],
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
dts: './src/components.d.ts',
}),
UnocssVitePlugin(),
Layouts(),
],
define: {
'process.env': {},
'__DEV__': process.env.NODE_ENV !== 'production',
'__VUE_OPTIONS_API__': 'true',
'__VUE_PROD_DEVTOOLS__': 'false',
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': 'false',
},
resolve: {
alias: {
'@': fileURLToPath(new URL('src', import.meta.url)),
'@vuetify/v0': fileURLToPath(new URL('../../packages/0/src', import.meta.url)),
'#v0': fileURLToPath(new URL('../../packages/0/src', import.meta.url)),
},
},
server: {
fs: {
allow: ['../../packages/*', '../../node_modules', '.'],
},
},
})