Skip to navigation

@mdx-js/rollup

MDX 的 Rollup(和 Vite)插件。

¥Rollup (and Vite) plugin for MDX.

内容

¥Contents

这是什么?

¥What is this?

该软件包是一个 Rollup(和 Vite)插件,用于支持 MDX。

¥This package is a Rollup (and Vite) plugin to support MDX.

我什么时候应该使用这个?

¥When should I use this?

如果你使用 Rollup(或使用 Rollup 的其他工具,例如 Vite),此集成非常有用。

¥This integration is useful if you’re using Rollup (or another tool that uses Rollup, such as Vite).

这种集成可以与 Babel 插件相结合,将现代 JavaScript 功能编译为用户支持的功能。

¥This integration can be combined with the Babel plugin to compile modern JavaScript features to ones your users support.

如果你想评估 MDX 代码,则可以手动使用更底层的编译器 (@mdx-js/mdx)。

¥If you want to evaluate MDX code then the lower-level compiler (@mdx-js/mdx) can be used manually.

安装

¥Install

这个包是 仅限 ESM。在 Node.js(版本 16+)中,使用 npm 安装:

¥This package is ESM only. In Node.js (version 16+), install with npm:

Shell
npm install @mdx-js/rollup

使用

¥Use

将以下内容添加到你的 rollup.config.js 中:

¥Add something along these lines to your rollup.config.js:

TypeScript
import mdx from '@mdx-js/rollup'

/** @type {import('rollup').RollupOptions} */
const config = {
  // …
  plugins: [
    // …
    mdx({/* jsxImportSource: …, otherOptions… */})
  ]
}

export default config

如果你通过它们使用 Rollup,另请参阅 ¶ Vite 以获取更多信息。

¥See also ¶ Vite if you’re using Rollup through them for more info.

API

该包不导出任何标识符。默认导出为 mdx

¥This package exports no identifiers. The default export is mdx.

mdx(options?)

用于编译 MDX w/ rollup 的插件。

¥Plugin to compile MDX w/ rollup.

参数

¥Parameters

  • optionsOptions,可选) - 配置

    ¥options (Options, optional) — configuration

返回

¥Returns

Rollup(和 Vite)插件。

¥Rollup (and Vite) plugin.

Options

配置(TypeScript 类型)。

¥Configuration (TypeScript type).

选项与 CompileOptions@mdx-js/mdx 相同,但根据你配置 Rollup 的方式支持 SourceMapGenerator 选项。你无法手动传递它。使用 Vite 时,根据你配置 Vite 的方式,也支持 development 选项。

¥Options are the same as CompileOptions from @mdx-js/mdx with the exception that the SourceMapGenerator option is supported based on how you configure Rollup. You cannot pass it manually. When using Vite, the development option is also supported based on how you configure Vite.

还有两个附加选项:

¥There are also two additional options:

字段

¥Fields

  • excludeArray<RegExp | string>RegExpstring,可选)— 要排除的 picomatch 模式

    ¥exclude (Array<RegExp | string>, RegExp, or string, optional) — picomatch patterns to exclude

  • includeArray<RegExp | string>RegExpstring,可选)— 要包含的 picomatch 模式

    ¥include (Array<RegExp | string>, RegExp, or string, optional) — picomatch patterns to include

示例

¥Examples

与 Babel 结合

¥Combine with Babel

如果你使用现代 JavaScript 功能,你可能希望通过 @rollup/plugin-babel 使用 Babel 来编译为有效的代码:

¥If you use modern JavaScript features you might want to use Babel through @rollup/plugin-babel to compile to code that works:

TypeScript
import mdx from '@mdx-js/rollup'
import {babel} from '@rollup/plugin-babel'

/** @type {import('rollup').RollupOptions} */
const config = {
  // …
  plugins: [
    // …
    mdx({/* jsxImportSource: …, otherOptions… */}),
    babel({
      // Also run on what used to be `.mdx` (but is now JS):
      extensions: ['.js', '.jsx', '.cjs', '.mjs', '.md', '.mdx']
      // Other options…
    })
  ]
}

export default config

类型

¥Types

该包完全采用 TypeScript 类型。它导出附加类型 Options。请参阅我们网站上的 § 类型 了解信息。

¥This package is fully typed with TypeScript. It exports the additional type Options. See § Types on our website for information.

兼容性

¥Compatibility

由统一集体维护的项目与 Node.js 的维护版本兼容。

¥Projects maintained by the unified collective are compatible with maintained versions of Node.js.

当我们削减新的主要版本时,我们会放弃对未维护的 Node.js 版本的支持。这意味着我们尝试保持当前版本 @mdx-js/rollup@^3 与 Node.js 16 兼容。

¥When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, @mdx-js/rollup@^3, compatible with Node.js 16.

安全

¥Security

请参阅我们网站上的 § 安全 了解信息。

¥See § Security on our website for information.

贡献

¥Contribute

请参阅我们网站上的 § 贡献 了解入门方法。请参阅 § 支持 了解获取帮助的方法。

¥See § Contribute on our website for ways to get started. See § Support for ways to get help.

该项目有 行为守则。通过与此存储库、组织或社区交互,你同意遵守其条款。

¥This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

许可证

¥License

MIT © Titus Wormer

MDX 中文网 - 粤ICP备13048890号