Convert .mdx files to standalone HTML with embedded React components.
The output is a single self-contained .html file — no server required. Open it directly in a browser.
npm install -g @imminent/mdx-render# Basic conversion — outputs my-doc.html
mdx-render my-doc.mdx
# Specify output file
mdx-render my-doc.mdx -o dist/index.html
# Add a custom page title
mdx-render my-doc.mdx --title "My Document"
# Inline a CSS file
mdx-render my-doc.mdx --css styles.css
# Use a components config (see below)
mdx-render my-doc.mdx --config mdx-render.config.js| Option | Description |
|---|---|
<input> |
Path to the .mdx file to convert |
-o, --output <file> |
Output HTML file path (default: <input-name>.html) |
-c, --config <file> |
Path to components config (auto-discovers mdx-render.config.js) |
--title <title> |
HTML <title> tag content (default: input filename) |
--css <file> |
Path to a CSS file to inline into the output HTML |
-V, --version |
Print version number |
-h, --help |
Print help |
npx mdx-render my-doc.mdxMDX files can use custom React components. To make them available during bundling, create a config file:
// mdx-render.config.js
import { MyChart } from './components/MyChart.jsx'
import { CodeBlock } from './components/CodeBlock.jsx'
export const components = {
MyChart,
CodeBlock,
}Then run:
mdx-render my-doc.mdx --config mdx-render.config.jsOr place mdx-render.config.js in the same directory where you run the command — it will be picked up automatically.
Inside your .mdx file, use components by name:
# Hello
<MyChart data={[1, 2, 3]} />
Some text with a <CodeBlock lang="js">console.log('hi')</CodeBlock>Note: The config file and its imports are bundled using esbuild. Your components' own dependencies must be installed in a
node_modulesdirectory reachable from the config file. React itself is provided bymdx-render— you do not need React in your project.
- The
.mdxfile is compiled to a JavaScript ES module using@mdx-js/mdx. - The compiled module is bundled with React (included),
react-dom/client, and any custom components usingesbuildinto a single minified IIFE script. - The script is embedded in a minimal HTML file alongside a
<div id="root">. - When the HTML file is opened in a browser, React mounts and renders the MDX content.
MIT