forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
59 lines (57 loc) · 1.52 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
import fs from 'node:fs'
import type { Plugin } from 'vite'
import { defineConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
import Unocss from 'unocss/vite'
import { presetAttributify, presetIcons, presetUno } from 'unocss'
import { resolve } from 'pathe'
export default defineConfig({
optimizeDeps: {
// vitepress is aliased with replacement `join(DIST_CLIENT_PATH, '/index')`
// This needs to be excluded from optimization
exclude: ['@vueuse/core', 'vitepress'],
},
server: {
hmr: {
overlay: false,
},
},
plugins: [
Components({
include: [/\.vue/, /\.md/],
dirs: '.vitepress/components',
dts: '.vitepress/components.d.ts',
}) as Plugin,
Unocss({
shortcuts: [
['btn', 'px-4 py-1 rounded inline-flex justify-center gap-2 text-white leading-30px children:mya !no-underline cursor-pointer disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
],
presets: [
presetUno({
dark: 'media',
}),
presetAttributify(),
presetIcons({
scale: 1.2,
}),
],
}),
IncludesPlugin(),
],
})
function IncludesPlugin(): Plugin {
return {
name: 'include-plugin',
enforce: 'pre',
transform(code, id) {
let changed = false
code = code.replace(/\[@@include\]\((.*?)\)/, (_, url) => {
changed = true
const full = resolve(id, url)
return fs.readFileSync(full, 'utf-8')
})
if (changed)
return code
},
}
}