-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
37 lines (33 loc) · 1.05 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
import { sveltekit } from "@sveltejs/kit/vite";
import pluginYaml from "@rollup/plugin-yaml";
import yaml from "js-yaml";
import { dataToEsm } from "@rollup/pluginutils";
import type { UserConfig } from "vite";
/** A custom Markdown plugin for Vite, with TOML frontmatter support. */
function markdown() {
return {
name: "markdown",
transform(src: string, id: string) {
if (/\.md$/.test(id)) {
let frontmatter = {};
let content = src;
if (src.startsWith("---")) {
const end = src.indexOf("---", 3);
if (end === -1) {
throw new Error(`Unclosed TOML frontmatter in ${id}`);
}
frontmatter = yaml.load(src.substring(3, end).trim()) as any;
content = src.substring(end + 3).trim();
}
return {
code: dataToEsm({ ...frontmatter, content }),
map: null,
};
}
},
};
}
const config: UserConfig = {
plugins: [sveltekit(), pluginYaml() as any, markdown()],
};
export default config;