@zikojs/vite-plugin-mdx 0.4.0 → 0.4.2
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 +3 -1
- package/src/index.js +13 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zikojs/vite-plugin-mdx",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Vite plugin for Zikojs MDX support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zikojs",
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"type": "module",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"ziko": "^1.10.0",
|
|
39
|
+
"vite": "^8.2.1",
|
|
40
|
+
"@rollup/pluginutils": "^5.4.0",
|
|
39
41
|
"@zikojs/mdx": "0.3.1"
|
|
40
42
|
},
|
|
41
43
|
"scripts": {
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { createFilter } from "vite";
|
|
2
3
|
import { transpileMD } from "@zikojs/mdx";
|
|
3
4
|
|
|
@@ -6,45 +7,43 @@ export default function ViteMDX({
|
|
|
6
7
|
syntaxHighlightAdapter = null,
|
|
7
8
|
marker = "",
|
|
8
9
|
include = ["**/*"],
|
|
10
|
+
exclude,
|
|
9
11
|
} = {}) {
|
|
10
12
|
const extensions = [".mdx", ".md"];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
let includeFilter;
|
|
14
|
+
let root;
|
|
15
|
+
const cleanId = (id) => id.replace(/\\/g, "/").split("?")[0].split("#")[0];
|
|
14
16
|
const isMarkdownFile = (id) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const clean = cleanId(id);
|
|
18
|
+
if (!includeFilter(clean)) return false;
|
|
17
19
|
return extensions.some((ext) =>
|
|
18
20
|
marker
|
|
19
|
-
?
|
|
20
|
-
:
|
|
21
|
+
? clean.endsWith(`${marker}${ext}`)
|
|
22
|
+
: clean.endsWith(ext)
|
|
21
23
|
);
|
|
22
24
|
};
|
|
23
|
-
|
|
24
25
|
return {
|
|
25
26
|
name: "@zikojs/vite-plugin-mdx",
|
|
26
|
-
|
|
27
|
+
configResolved(config) {
|
|
28
|
+
root = path.resolve(config.root).replace(/\\/g, "/");
|
|
29
|
+
includeFilter = createFilter(include, exclude, { resolve: root });
|
|
30
|
+
},
|
|
27
31
|
async transform(src, id) {
|
|
28
32
|
if (!isMarkdownFile(id)) return;
|
|
29
|
-
|
|
30
33
|
const code = await transpileMD(src, {
|
|
31
34
|
plugins,
|
|
32
35
|
syntaxHighlightAdapter,
|
|
33
36
|
});
|
|
34
|
-
|
|
35
37
|
return {
|
|
36
38
|
code,
|
|
37
39
|
map: null,
|
|
38
40
|
};
|
|
39
41
|
},
|
|
40
|
-
|
|
41
42
|
handleHotUpdate({ file, server }) {
|
|
42
43
|
if (!isMarkdownFile(file)) return;
|
|
43
|
-
|
|
44
44
|
server.ws.send({
|
|
45
45
|
type: "full-reload",
|
|
46
46
|
});
|
|
47
|
-
|
|
48
47
|
// server.ws.send({
|
|
49
48
|
// type: "custom",
|
|
50
49
|
// event: "custom-update",
|
|
@@ -53,7 +52,6 @@ export default function ViteMDX({
|
|
|
53
52
|
// timestamp: Date.now(),
|
|
54
53
|
// },
|
|
55
54
|
// });
|
|
56
|
-
|
|
57
55
|
return [file];
|
|
58
56
|
},
|
|
59
57
|
};
|