Skip to content
ironmark

esbuild and Bun

ironmark/esbuild works in esbuild, tsup and Bun.

import * as esbuild from "esbuild";
import ironmarkMdx from "ironmark/esbuild";
 
await esbuild.build({
  entryPoints: ["src/main.jsx"],
  bundle: true,
  jsx: "automatic",
  plugins: [ironmarkMdx()],
});

The plugin returns the compiled module with the jsx loader, so esbuild finishes the JSX itself. Imports inside an .mdx file resolve relative to it. Compile errors are reported with the file location.

Bun

The same plugin works in Bun.build():

import ironmarkMdx from "ironmark/esbuild";
 
await Bun.build({ entrypoints: ["src/main.jsx"], plugins: [ironmarkMdx()] });

To import .md and .mdx at runtime, register it with Bun.plugin() in a preload script:

// preload.js
import ironmarkMdx from "ironmark/esbuild";
 
Bun.plugin(ironmarkMdx());

tsup

// tsup.config.js
import ironmarkMdx from "ironmark/esbuild";
 
export default {
  entry: ["src/index.tsx"],
  esbuildPlugins: [ironmarkMdx()],
};

See options for everything the plugin accepts.