@rsbuild/plugin-mdx 0.7.10 → 1.0.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
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
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
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
- # Rsbuild
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
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
65
+ ```ts
66
+ pluginMdx({
67
+ extensions: [".mdx"],
68
+ });
69
+ ```
8
70
 
9
- ## Documentation
71
+ ## Type Declarations
10
72
 
11
- https://rsbuild.dev/
73
+ In a TypeScript project, you need to add type definitions for `*.mdx` files so that TypeScript can recognize them correctly.
12
74
 
13
- ## Contributing
75
+ Create `env.d.ts` in the `src` directory and add the following content:
14
76
 
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
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
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
90
+ [MIT](./LICENSE).
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -34,6 +24,13 @@ __export(src_exports, {
34
24
  pluginMdx: () => pluginMdx
35
25
  });
36
26
  module.exports = __toCommonJS(src_exports);
27
+
28
+ // node_modules/.pnpm/tsup@8.0.2_postcss@8.4.38_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js
29
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
30
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
31
+
32
+ // src/index.ts
33
+ var import_node_module = require("module");
37
34
  function createRegExp(exts) {
38
35
  const matcher = exts.map((ext) => ext.slice(1)).join("|");
39
36
  return new RegExp(
@@ -61,7 +58,8 @@ var pluginMdx = (options = {}) => ({
61
58
  return false;
62
59
  });
63
60
  const MDX_REGEXP = createRegExp(extensions);
64
- mdxRule.test(MDX_REGEXP).use("mdx").loader(require.resolve("@mdx-js/loader")).options(options.mdxLoaderOptions ?? {});
61
+ const require2 = (0, import_node_module.createRequire)(importMetaUrl);
62
+ mdxRule.test(MDX_REGEXP).use("mdx").loader(require2.resolve("@mdx-js/loader")).options(options.mdxLoaderOptions ?? {});
65
63
  const { REACT_FAST_REFRESH } = CHAIN_ID.PLUGIN;
66
64
  if (chain.plugins.has(REACT_FAST_REFRESH)) {
67
65
  chain.plugins.get(REACT_FAST_REFRESH).tap((options2) => {
@@ -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,19 +1,5 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined")
8
- return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
10
- });
11
-
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
1
  // src/index.ts
2
+ import { createRequire } from "node:module";
17
3
  function createRegExp(exts) {
18
4
  const matcher = exts.map((ext) => ext.slice(1)).join("|");
19
5
  return new RegExp(
@@ -41,7 +27,8 @@ var pluginMdx = (options = {}) => ({
41
27
  return false;
42
28
  });
43
29
  const MDX_REGEXP = createRegExp(extensions);
44
- mdxRule.test(MDX_REGEXP).use("mdx").loader(__require.resolve("@mdx-js/loader")).options(options.mdxLoaderOptions ?? {});
30
+ const require2 = createRequire(import.meta.url);
31
+ mdxRule.test(MDX_REGEXP).use("mdx").loader(require2.resolve("@mdx-js/loader")).options(options.mdxLoaderOptions ?? {});
45
32
  const { REACT_FAST_REFRESH } = CHAIN_ID.PLUGIN;
46
33
  if (chain.plugins.has(REACT_FAST_REFRESH)) {
47
34
  chain.plugins.get(REACT_FAST_REFRESH).tap((options2) => {
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-mdx",
3
- "version": "0.7.10",
4
- "description": "Mdx plugin for Rsbuild",
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.1",
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.cjs",
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
- "typescript": "^5.4.2",
31
- "@rsbuild/core": "0.7.10"
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": "^0.7.10"
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": "modern build",
43
- "dev": "modern build --watch"
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
  }