Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zaydek/esbuild-mdx

esbuild plugin for rendering markdown as React components
https://github.com/zaydek/esbuild-mdx

Last synced: about 2 months ago
JSON representation

esbuild plugin for rendering markdown as React components

Awesome Lists containing this project

README

        

# esbuild-mdx

`esbuild-mdx` resolves `.md` and `.mdx`-delimited files as markdown components you can render in your React components.

- Add dependencies:

```sh
yarn add react react-dom
yarn add --dev @mdx-js/react esbuild-mdx
```

- Create [`esbuild.js`](https://github.com/zaydek/esbuild-mdx-example/blob/master/esbuild.js):

```js
require("esbuild").build({
// ...
plugins: [require("esbuild-mdx")()],
// ...
})
```

- Create a `.md` or `.mdx`-delimited file:

```md
# Hello, world rendered by `esbuild-mdx`!
```

- Import your `.md` or `.mdx` file and render as a React component:

```jsx
import React from "react"
import ReactDOM from "react-dom"

import MarkdownComponent from "./example.md"

function App() {
return (



Hello, world rendered by React!




)
}

ReactDOM.render(, document.getElementById("root"))
```

See [esbuild-mdx-example](https://github.com/zaydek/esbuild-mdx-example) for a reference implementation.

**Note:** `react`, `react-dom`, and `@mdx-js/react` are peer dependencies.

## License

Licensed as MIT open source.