Skip to content

mdxLoader

mdxLoader<T>(schema, config): LoaderReturn<T>

Defined in: packages/core/src/loaders.ts:230

Loads and processes MDX files from a directory, bundling them and validating against a schema. Extracts frontmatter, compiles MDX to executable code, and optionally captures named exports.

T extends AnyStruct

The schema type extending AnyStruct

T

Effect Schema used to validate the combined frontmatter and metadata

Configuration object

Omit<Parameters<typeof bundleMDX>[0], "source" | "file">

Options passed to mdx-bundler (excluding ‘source’ and ‘file’)

string[]

Optional array of export names to extract from the MDX module

string

Path to the directory containing MDX files

LoaderReturn<T>

A Stream of validated objects containing frontmatter and a meta object with mdx code, raw content, and exports

When no MDX files are found, bundling fails, or validation fails

const PostSchema = Schema.Struct({
title: Schema.String,
date: Schema.String,
meta: Schema.Struct({
mdx: Schema.String,
raw: Schema.String,
exports: Schema.Record(Schema.String, Schema.Unknown),
}),
});
const posts = mdxLoader(PostSchema, {
folder: './content/posts',
bundlerOptions: { cwd: process.cwd() },
exports: ['metadata', 'getStaticProps'],
});