@zikojs/vite-plugin-mdx 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +49 -28
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,39 +1,60 @@
|
|
|
1
|
+
import { createFilter } from "vite";
|
|
1
2
|
import { transpileMD } from "@zikojs/mdx";
|
|
2
3
|
|
|
3
|
-
export default function ViteMDX({
|
|
4
|
-
extensions = [".mdx"],
|
|
4
|
+
export default function ViteMDX({
|
|
5
5
|
plugins,
|
|
6
|
-
syntaxHighlightAdapter = null
|
|
6
|
+
syntaxHighlightAdapter = null,
|
|
7
|
+
marker = "",
|
|
8
|
+
include = ["**/*"],
|
|
7
9
|
} = {}) {
|
|
10
|
+
const extensions = [".mdx", ".md"];
|
|
11
|
+
|
|
12
|
+
const includeFilter = createFilter(include);
|
|
13
|
+
|
|
14
|
+
const isMarkdownFile = (id) => {
|
|
15
|
+
if (!includeFilter(id)) return false;
|
|
16
|
+
|
|
17
|
+
return extensions.some((ext) =>
|
|
18
|
+
marker
|
|
19
|
+
? id.endsWith(`${marker}${ext}`)
|
|
20
|
+
: id.endsWith(ext)
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
8
24
|
return {
|
|
9
|
-
name: "@zikojs/mdx
|
|
25
|
+
name: "@zikojs/vite-plugin-mdx",
|
|
26
|
+
|
|
10
27
|
async transform(src, id) {
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
if (!isMarkdownFile(id)) return;
|
|
29
|
+
|
|
30
|
+
const code = await transpileMD(src, {
|
|
31
|
+
plugins,
|
|
32
|
+
syntaxHighlightAdapter,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
code,
|
|
37
|
+
map: null,
|
|
38
|
+
};
|
|
18
39
|
},
|
|
19
40
|
|
|
20
41
|
handleHotUpdate({ file, server }) {
|
|
21
|
-
if (file
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
if (!isMarkdownFile(file)) return;
|
|
43
|
+
|
|
44
|
+
server.ws.send({
|
|
45
|
+
type: "full-reload",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// server.ws.send({
|
|
49
|
+
// type: "custom",
|
|
50
|
+
// event: "custom-update",
|
|
51
|
+
// data: {
|
|
52
|
+
// file,
|
|
53
|
+
// timestamp: Date.now(),
|
|
54
|
+
// },
|
|
55
|
+
// });
|
|
56
|
+
|
|
57
|
+
return [file];
|
|
37
58
|
},
|
|
38
59
|
};
|
|
39
|
-
}
|
|
60
|
+
}
|