-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
76 lines (71 loc) · 2.22 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
import fastGlob from 'fast-glob'
import { readFileSync } from 'fs'
import matter from 'gray-matter'
import { configureable, Testable } from '@baleada/prepare'
import {
proseToVueSfc,
proseFilesToManifest,
proseFilesToSearchableCandidates,
} from './source-transforms'
// Exclude any page whose frontmatter has `publish: false`
function toExclude (pagesDir: string): string[] {
return fastGlob.sync(`${pagesDir}/**/*.md`).filter(
file => !testRoute({ source: readFileSync(file, 'utf8'), id: file })
)
}
const testRoute = ({ source, id }) => {
const { data: { publish } } = matter(source)
return publish && id.endsWith('.md')
}
export default new configureable.Vite()
.alias({
'virtual:manifest': '/src/state/manifest.ts',
'virtual:searchableCandidates': '/src/state/searchableCandidates.ts',
'@composition': '/src/composition/index.ts',
'@octicons': '/node_modules/@primer/octicons/build/svg',
'@simple-icons': '/node_modules/simple-icons/icons',
})
.excludeDeps([
'virtual:manifest',
'virtual:searchableCandidates',
])
.sourceTransform({
transform: proseToVueSfc,
test: ({ id }) => id.endsWith('.md'),
})
.pages({
pagesDir: 'src/prose',
extensions: ['md'],
exclude: toExclude('src/prose'),
extendRoute: route => {
switch (route.path) {
case '/':
route.path = '/docs'
break
default:
route.path = `/docs${route.path}`
break
}
return route
}
})
.sourceTransform({
test: param => new Testable().include(/(@primer\/octicons|simple-icons|src\/icons)/).test(param),
transform: ({ id }) => toIconSfc(readFileSync(`${id}`, { encoding: 'utf8' })),
})
.virtual({
test: param => new Testable().idEndsWith('src/state/manifest.ts').test(param),
transform: () => proseFilesToManifest(),
})
.virtual({
test: param => new Testable().idEndsWith('src/state/searchableCandidates.ts').test(param),
transform: () => proseFilesToSearchableCandidates(),
})
.vue({
include: ['**/*.vue', '**/*.md', '**/*.svg'],
})
.inspect()
.configure()
function toIconSfc (svg: string) {
return `<template>${svg.replace(/svg/, 'svg aria-hidden="true" class="fill-current"')}</template>`
}