@rsbuild/plugin-mdx 0.7.10 → 1.0.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/LICENSE +1 -1
- package/README.md +80 -9
- package/dist/index.d.cts +18 -0
- package/dist/index.js +0 -7
- package/package.json +41 -17
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Rspack Contrib
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,19 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# @rsbuild/plugin-mdx
|
|
2
|
+
|
|
3
|
+
An Rsbuild plugin to provide support for [MDX](https://github.com/mdx-js/mdx/).
|
|
4
|
+
|
|
5
|
+
MDX lets you use JSX in your markdown content. You can import components, such as interactive charts or alerts, and embed them within your content. This makes writing long-form content with components a blast.
|
|
6
|
+
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://npmjs.com/package/@rsbuild/plugin-mdx">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-mdx?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
10
|
+
</a>
|
|
11
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
3
12
|
</p>
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Install:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm add @rsbuild/plugin-mdx -D
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Add plugin to your `rsbuild.config.ts`:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// rsbuild.config.ts
|
|
26
|
+
import { pluginMdx } from "@rsbuild/plugin-mdx";
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
plugins: [pluginMdx()],
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
After registering the plugin, you can import `.mdx` or `.md` files as components in your code.
|
|
34
|
+
|
|
35
|
+
## Options
|
|
36
|
+
|
|
37
|
+
If you need to customize the compilation behavior of MDX, you can use the following configs.
|
|
38
|
+
|
|
39
|
+
### mdxLoaderOptions
|
|
40
|
+
|
|
41
|
+
Options passed to `@mdx-js/loader`, please refer to [@mdx-js/loader documentation](https://www.npmjs.com/package/@mdx-js/loader) for detailed usage.
|
|
42
|
+
|
|
43
|
+
- **Type:** `MdxLoaderOptions`
|
|
44
|
+
- **Default:** `{}`
|
|
45
|
+
- **Example:**
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
pluginMdx({
|
|
49
|
+
mdxLoaderOptions: {
|
|
50
|
+
// Use Vue JSX
|
|
51
|
+
jsxImportSource: "vue",
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### extensions
|
|
57
|
+
|
|
58
|
+
Specify the file extensions to be compiled with MDX loader, including .md files and .mdx files by default.
|
|
59
|
+
|
|
60
|
+
- **Type:** `string[]`
|
|
61
|
+
- **Default:** `['.mdx', '.md']`
|
|
62
|
+
|
|
63
|
+
For example, to only compile .mdx files, you can set it as:
|
|
6
64
|
|
|
7
|
-
|
|
65
|
+
```ts
|
|
66
|
+
pluginMdx({
|
|
67
|
+
extensions: [".mdx"],
|
|
68
|
+
});
|
|
69
|
+
```
|
|
8
70
|
|
|
9
|
-
##
|
|
71
|
+
## Type Declarations
|
|
10
72
|
|
|
11
|
-
|
|
73
|
+
In a TypeScript project, you need to add type definitions for `*.mdx` files so that TypeScript can recognize them correctly.
|
|
12
74
|
|
|
13
|
-
|
|
75
|
+
Create `env.d.ts` in the `src` directory and add the following content:
|
|
14
76
|
|
|
15
|
-
|
|
77
|
+
```ts title="src/env.d.ts"
|
|
78
|
+
declare module "*.md" {
|
|
79
|
+
let MDXComponent: () => JSX.Element;
|
|
80
|
+
export default MDXComponent;
|
|
81
|
+
}
|
|
82
|
+
declare module "*.mdx" {
|
|
83
|
+
let MDXComponent: () => JSX.Element;
|
|
84
|
+
export default MDXComponent;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
16
87
|
|
|
17
88
|
## License
|
|
18
89
|
|
|
19
|
-
|
|
90
|
+
[MIT](./LICENSE).
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Options } from '@mdx-js/loader';
|
|
2
|
+
import { RsbuildPlugin } from '@rsbuild/core';
|
|
3
|
+
|
|
4
|
+
type PluginMdxOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Options passed to `@mdx-js/loader`.
|
|
7
|
+
* @see https://npmjs.com/package/@mdx-js/loader#api
|
|
8
|
+
*/
|
|
9
|
+
mdxLoaderOptions?: Options;
|
|
10
|
+
/**
|
|
11
|
+
* @default ['.mdx', '.md']
|
|
12
|
+
*/
|
|
13
|
+
extensions?: string[];
|
|
14
|
+
};
|
|
15
|
+
declare const PLUGIN_MDX_NAME = "rsbuild:mdx";
|
|
16
|
+
declare const pluginMdx: (options?: PluginMdxOptions) => RsbuildPlugin;
|
|
17
|
+
|
|
18
|
+
export { PLUGIN_MDX_NAME, type PluginMdxOptions, pluginMdx };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
var require = createRequire(import.meta['url']);
|
|
3
|
-
|
|
4
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
3
|
}) : x)(function(x) {
|
|
@@ -9,10 +6,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
7
|
});
|
|
11
8
|
|
|
12
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.5.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
|
|
13
|
-
import { fileURLToPath } from "url";
|
|
14
|
-
import path from "path";
|
|
15
|
-
|
|
16
9
|
// src/index.ts
|
|
17
10
|
function createRegExp(exts) {
|
|
18
11
|
const matcher = exts.map((ext) => ext.slice(1)).join("|");
|
package/package.json
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-mdx",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"homepage": "https://rsbuild.dev",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/web-infra-dev/rsbuild",
|
|
9
|
-
"directory": "packages/plugin-mdx"
|
|
10
|
-
},
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-mdx",
|
|
11
5
|
"license": "MIT",
|
|
12
6
|
"type": "module",
|
|
13
7
|
"exports": {
|
|
@@ -17,29 +11,59 @@
|
|
|
17
11
|
"require": "./dist/index.cjs"
|
|
18
12
|
}
|
|
19
13
|
},
|
|
20
|
-
"main": "./dist/index.
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
21
16
|
"types": "./dist/index.d.ts",
|
|
22
17
|
"files": [
|
|
23
18
|
"dist"
|
|
24
19
|
],
|
|
20
|
+
"simple-git-hooks": {
|
|
21
|
+
"pre-commit": "npx nano-staged"
|
|
22
|
+
},
|
|
23
|
+
"nano-staged": {
|
|
24
|
+
"*.{js,jsx,ts,tsx,mjs,cjs}": [
|
|
25
|
+
"biome check --write --no-errors-on-unmatched"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@mdx-js/loader": "^3.0.1"
|
|
27
|
-
"@rsbuild/shared": "0.7.10"
|
|
29
|
+
"@mdx-js/loader": "^3.0.1"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
|
-
"
|
|
31
|
-
"@
|
|
32
|
+
"@biomejs/biome": "^1.8.3",
|
|
33
|
+
"@playwright/test": "^1.44.1",
|
|
34
|
+
"@rsbuild/core": "^0.7.10",
|
|
35
|
+
"@rsbuild/plugin-preact": "^0.7.10",
|
|
36
|
+
"@rsbuild/plugin-react": "^0.7.10",
|
|
37
|
+
"@rsbuild/plugin-svgr": "^0.7.10",
|
|
38
|
+
"@rsbuild/plugin-vue": "^0.7.10",
|
|
39
|
+
"@types/node": "^20.14.1",
|
|
40
|
+
"nano-staged": "^0.8.0",
|
|
41
|
+
"playwright": "^1.44.1",
|
|
42
|
+
"preact": "^10.22.1",
|
|
43
|
+
"react": "^18.3.1",
|
|
44
|
+
"react-dom": "^18.3.1",
|
|
45
|
+
"simple-git-hooks": "^2.11.1",
|
|
46
|
+
"tsup": "^8.0.2",
|
|
47
|
+
"typescript": "^5.5.2",
|
|
48
|
+
"vue": "^3.4.31"
|
|
32
49
|
},
|
|
33
50
|
"peerDependencies": {
|
|
34
|
-
"@rsbuild/core": "
|
|
51
|
+
"@rsbuild/core": "0.x || 1.x"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@rsbuild/core": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
35
57
|
},
|
|
36
58
|
"publishConfig": {
|
|
37
59
|
"access": "public",
|
|
38
|
-
"provenance": true,
|
|
39
60
|
"registry": "https://registry.npmjs.org/"
|
|
40
61
|
},
|
|
41
62
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"dev": "
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"dev": "tsup --watch",
|
|
65
|
+
"lint": "biome check .",
|
|
66
|
+
"lint:write": "biome check . --write",
|
|
67
|
+
"test": "playwright test"
|
|
44
68
|
}
|
|
45
69
|
}
|