A native MDX content compiler
Give @amamo/mdx a directory of MDX files and a Zod object schema. A build converts the schema to
JSON Schema, validates the frontmatter, compiles each document for the configured JSX runtime (React
by default), highlights fenced code with Shiki, and writes a collection registry, companion
declaration, and configured manifests.
pnpm add @amamo/mdxnpm install @amamo/mdxyarn add @amamo/mdxbun add @amamo/mdxChoose a path
| I want to... | Start here |
|---|---|
| Compile content in a Vite app | Vite 8 |
| Import MDX in a Next app | Next 16 |
| Drive builds from my own script | Compiler API |
| See every config default | Configuration |
One document through the pipeline
MDX source + config
-> TypeScript: Zod to JSON Schema, discovery, operation queue
-> Rust: YAML, JSON Schema, MDX tree, media, derived fields
-> JavaScript: official Shiki themes, grammars, and engine
-> Rust: highlighted module, validated metadata, manifest projections, cache record
-> TypeScript: collections.mjs, collections.d.ts, index.json, manifestsRust owns parsing, validation, MDX compilation, manifest projection, and persistent records. Shiki stays in JavaScript; its highlighted HAST is validated and injected before Rust emits the final module. The direct API, Vite plugin, and Next wrapper share this implementation, but each compiler or adapter instance owns its own state.
What a build gives you
- A JavaScript module for every imported MDX document, including
frontmatterand enabled derived exports. collections.mjs, a deterministic registry of document metadata and lazy source imports.collections.d.ts, a companion declaration output for the registry.- Optional JSON manifests with explicit field projection, sorting, and array or keyed-object output.
- BLAKE3-addressed cache records so unchanged documents can skip native compilation and Shiki.
Relative media URLs written in Markdown become static imports after fresh-compilation root checks. Authored MDX JSX is compiled as part of MDX, but media attributes inside it are not rewritten.
Deliberate boundaries
- Trusted content only. MDX can execute JavaScript when its compiled module is imported or rendered. Schema validation is not a sandbox.
- Build-time compiler, not a runtime. The host imports or renders emitted modules with the configured JSX runtime.
- Plain-data configuration. Functions, class instances, symbols, accessors, cycles, and non-finite numbers are rejected after the config value is loaded.
- Native targets only. There is no JavaScript or WASI fallback. See Native targets.
Continue with Getting started for a complete first document.