@zikojs/vite-plugin-mdx 0.1.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.
Files changed (2) hide show
  1. package/package.json +44 -0
  2. package/src/index.js +35 -0
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@zikojs/vite-plugin-mdx",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Zikojs MDX support",
5
+ "keywords": [
6
+ "zikojs",
7
+ "mdx",
8
+ "vite",
9
+ "preprocessor",
10
+ "transpiler"
11
+ ],
12
+ "homepage": "https://github.com/zikojs/mdx#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/zikojs/mdx/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/zikojs/mdx.git",
19
+ "directory": "packages/vite-plugin-mdx"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "import": "./src/index.js",
27
+ "types": "./src/index.d.ts"
28
+ },
29
+ "./*": {
30
+ "import": "./src/*/index.js",
31
+ "types": "./src/*/index.d.ts"
32
+ }
33
+ },
34
+ "license": "MIT",
35
+ "author": "zakaria elalaoui",
36
+ "type": "module",
37
+ "dependencies": {
38
+ "ziko": "^1.10.0",
39
+ "@zikojs/mdx": "0.2.1"
40
+ },
41
+ "scripts": {
42
+ "test": "echo \"Error: no test specified\" && exit 1"
43
+ }
44
+ }
package/src/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { transpileMD } from "@zikojs/mdx";
2
+
3
+ export default function ViteMDX({ extensions = [".mdx"], plugins } = {}) {
4
+ return {
5
+ name: "@zikojs/mdx-loader",
6
+ async transform(src, id) {
7
+ if (id.endsWith(".mdz") || extensions.some((ext) => id.endsWith(ext))) {
8
+ const code = await transpileMD(src, {plugins});
9
+ return {
10
+ code,
11
+ map: null,
12
+ };
13
+ }
14
+ },
15
+
16
+ handleHotUpdate({ file, server }) {
17
+ if (file.endsWith(".mdx")) {
18
+ console.log({file})
19
+ server.ws.send({
20
+ type : 'full-reload'
21
+ })
22
+ // server.ws.send({
23
+ // type: "custom",
24
+ // event: "custom-update",
25
+ // data: {
26
+ // file,
27
+ // timestamp: Date.now(),
28
+ // },
29
+ // });
30
+
31
+ return [file];
32
+ }
33
+ },
34
+ };
35
+ }