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.
Type Parameters
Section titled “Type Parameters”T
extends AnyStruct
The schema type extending AnyStruct
Parameters
Section titled “Parameters”schema
Section titled “schema”T
Effect Schema used to validate the combined frontmatter and metadata
config
Section titled “config”Configuration object
bundlerOptions
Section titled “bundlerOptions”Omit
<Parameters
<typeof bundleMDX
>[0
], "source"
| "file"
>
Options passed to mdx-bundler (excluding ‘source’ and ‘file’)
exports?
Section titled “exports?”string
[]
Optional array of export names to extract from the MDX module
folder
Section titled “folder”string
Path to the directory containing MDX files
Returns
Section titled “Returns”LoaderReturn
<T
>
A Stream of validated objects containing frontmatter and a meta object with mdx code, raw content, and exports
Throws
Section titled “Throws”When no MDX files are found, bundling fails, or validation fails
Example
Section titled “Example”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'],});