-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
46 lines (40 loc) · 1.29 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
import build from "@hono/vite-build/cloudflare-pages";
import adapter from "@hono/vite-dev-server/cloudflare";
import honox from "honox/vite";
import { defineConfig } from "vite";
// import { mdx } from "@natsuneko-laboratory/honox-mdx-island";
import remarkFrontmatter from "remark-frontmatter";
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
const jsxImportSource = "hono/jsx";
// src/plugins/mdx-island.ts
import { compile, type CompileOptions } from "@mdx-js/mdx";
import precinct from "precinct";
import { type Plugin } from "vite";
const mdx = (opts: Readonly<CompileOptions>): Plugin => {
return {
name: "mdx-island",
async transform(source, id) {
if (id.endsWith(".mdx")) {
const code = await compile(source, opts);
const deps = precinct(code.value, { type: "tsx" }) as string[];
const hasIslands = deps.some((w) => /\/islands\/.*$/.test(w));
if (hasIslands) {
return {
code: `${code.value}\nexport const __importing_islands = true;`,
};
}
return { code: code.value };
}
},
};
};
export default defineConfig({
plugins: [
honox({ devServer: { adapter } }),
mdx({
jsxImportSource,
remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter],
}),
build(),
],
});