-
Notifications
You must be signed in to change notification settings - Fork 24
/
app.config.ts
140 lines (136 loc) · 4.39 KB
/
app.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
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
134
135
136
137
138
139
140
import { readFile } from "node:fs/promises";
import path from "node:path";
import yaml from "@rollup/plugin-yaml";
import rehypeShiki, { type RehypeShikiOptions } from "@shikijs/rehype";
import { transformerMetaHighlight } from "@shikijs/transformers";
import { defineConfig } from "@solidjs/start/config";
import vinxiMdxPkg from "@vinxi/plugin-mdx";
import rehypeSlug from "rehype-slug";
import remarkFrontmatter from "remark-frontmatter";
import remarkGfm from "remark-gfm";
import unocss from "unocss/vite";
import { imagetools } from "vite-imagetools";
// 현재 Vinxi export 설정 이슈로 파일을 직접 가져와야 함
import type { CustomizableConfig } from "./node_modules/vinxi/dist/types/lib/vite-dev";
import { indexFilesMapping } from "./src/misc/contentIndex";
const { default: vinxiMdx } = vinxiMdxPkg;
export default defineConfig({
server: {
preset: "vercel",
prerender: {
routes: [
...Object.keys(indexFilesMapping).map(
(fileName) => `/content-index/${fileName}.json`,
),
"/blog/rss.xml",
],
},
rollupConfig: {
external: ["monaco-editor"],
},
},
extensions: ["ts", "tsx", "mdx"],
vite: () =>
({
plugins: [
yaml(),
unocss(),
// eslint-disable-next-line
vinxiMdx.withImports({})({
jsx: true,
jsxImportSource: "solid-js",
providerImportSource: "solid-mdx",
remarkPlugins: [remarkFrontmatter, remarkGfm],
rehypePlugins: [
rehypeSlug,
[
rehypeShiki,
{
theme: "github-light",
fallbackLanguage: "text",
defaultLanguage: "text",
transformers: [
{
name: "remove-trailing-newline",
preprocess(code) {
if (code.endsWith("\n")) {
return code.slice(0, -1);
}
return code;
},
},
transformerMetaHighlight(),
{
name: "line-number-meta",
code(node) {
if (
this.options.meta?.__raw?.includes("showLineNumber")
) {
this.addClassToHast(node, "line-numbers");
}
},
},
{
name: "title",
pre(node) {
const matches = /title="([^"]+)"/.exec(
this.options.meta?.__raw ?? "",
);
if (matches?.[1]) {
node.children.unshift({
type: "element",
tagName: "div",
properties: {
className: ["title"],
},
children: [{ type: "text", value: matches[1] }],
});
}
},
},
],
} satisfies RehypeShikiOptions,
],
],
}),
imagetools({
defaultDirectives: (url) => {
const extname = path.extname(url.pathname);
if (
// formats supported by Sharp (https://sharp.pixelplumbing.com/#formats)
[
".png",
".jpg",
".jpeg",
".webp",
".gif",
".avif",
".tiff",
".tif",
".svg",
].includes(extname)
) {
return new URLSearchParams([
["as", "picture"],
["format", "webp"],
...url.searchParams.entries(),
]);
} else return url.searchParams;
},
}),
{
name: "base64-loader",
async transform(_, id) {
const [path, query] = id.split("?");
if (query !== "base64" || !path) return null;
const data = await readFile(path);
const base64 = data.toString("base64");
return `export default '${base64}';`;
},
},
],
}) satisfies CustomizableConfig,
solid: {
exclude: ["./src/misc/opengraph/**/*"],
},
});