Project: mdx-js/mdx

Package: @mdx-js/esbuild@2.2.1

  1. Dependents: 0
  2. esbuild plugin for MDX
  1. remark 209
  2. markdown 153
  3. mdx 35
  4. jsx 19
  5. react 15
  6. preact 5
  7. vue 5


Build Coverage Downloads Sponsors Backers Chat

esbuild plugin for MDX.


What is this?

This package is an esbuild plugin to support MDX.

When should I use this?

This integration is useful if you’re using esbuild (or another tool that uses esbuild).

If you want to evaluate MDX code then the lower-level compiler (@mdx-js/mdx) can be used. to support nonstandard JSX runtime (such as Vue), @mdx-js/mdx can also be used, or our webpack loader (@mdx-js/loader) or Rollup plugin (@mdx-js/rollup).


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install @mdx-js/esbuild


yarn add @mdx-js/esbuild


Do something like this with the esbuild API:

import esbuild from 'esbuild'
import mdx from '@mdx-js/esbuild'

await esbuild.build({
  entryPoints: ['index.mdx'],
  outfile: 'output.js',
  format: 'esm',
  plugins: [mdx({/* Options… */})]


This package exports a function as the default export that returns an esbuild plugin.


Create an esbuild plugin to compile MDX to JS.

esbuild takes care of turning modern JavaScript features into syntax that works wherever you want it to. With other integrations you might need to use Babel for this, but with esbuild that’s not needed. See esbuild’s docs for more info.


options are the same as compile from @mdx-js/mdx with the addition of:


⚠️ Security: this includes remote code in your bundle. Make sure you trust it! See § Security for more info.

💡 Experiment: this is an experimental feature that might not work well and might change in minor releases.

Whether to allow importing from http: and https: URLs (boolean, default: false).

When passing allowDangerousRemoteMdx, MD(X) and JS files can be imported from http: and https: urls. Take this index.mdx file:

import Readme from 'https://raw.githubusercontent.com/mdx-js/mdx/main/readme.md'

Here’s the readme:

<Readme />

And a module build.js:

import esbuild from 'esbuild'
import mdx from '@mdx-js/esbuild'

await esbuild.build({
  entryPoints: ['index.mdx'],
  outfile: 'output.js',
  format: 'esm',
  plugins: [mdx({allowDangerousRemoteMdx: true, /* Other options… */})]

Running that (node build.js) and evaluating output.js (depends on how you evaluate React stuff) would give:

<p>Here’s the readme:</p>
<h1>MDX: Markdown for the component era 🚀</h1>
{/* … */}
<p><a href="https://github.com/mdx-js/mdx/blob/main/license">MIT</a> © …</p>


This package is fully typed with TypeScript. See § Types on our website for information.

An Options type is exported, which represents acceptable configuration.


See § Security on our website for information.


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.


MIT © Titus Wormer