forked from theberlage/city-atlas-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
45 lines (40 loc) · 1022 Bytes
/
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
import { sveltekit } from '@sveltejs/kit/vite'
import type { UserConfig } from 'vite'
import path from 'path'
import { read } from 'to-vfile'
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkHtml from 'remark-html'
import remarkFrontmatter from 'remark-frontmatter'
import { matter } from 'vfile-matter'
function markdown() {
return {
name: 'markdown',
async load(id: string) {
if (/\.(md)$/.test(id)) {
const file = await unified()
.use(remarkParse)
.use(remarkHtml)
.use(remarkFrontmatter, ['yaml'])
.use(() => (_, file) => {
matter(file)
})
.process(await read(id))
return `
export const html = ${JSON.stringify(file.value)}
export const frontmatter = ${JSON.stringify(file.data.matter)}
`
}
}
}
}
const config: UserConfig = {
plugins: [markdown(), sveltekit()],
resolve: {
alias: {
$lib: path.resolve('./src/lib'),
$contents: path.resolve('./contents')
}
}
}
export default config