Astro integration that enables MDX support for creating interactive pages and components with Markdown and JSX
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core integration functionality for adding MDX support to Astro projects. The integration handles configuration, plugin setup, build system integration, and content collection support.
Creates an Astro integration that enables MDX support throughout the project.
/**
* Creates an Astro integration for MDX support
* @param partialMdxOptions - Optional configuration object for customizing MDX behavior
* @returns AstroIntegration object that hooks into Astro's build system
*/
export default function mdx(partialMdxOptions?: Partial<MdxOptions>): AstroIntegration;The returned AstroIntegration object contains:
name: "@astrojs/mdx"hooks: Integration hooks that run during different phases of the buildUsage Examples:
import { defineConfig } from "astro/config";
import mdx from "@astrojs/mdx";
// Basic usage with default settings
export default defineConfig({
integrations: [mdx()],
});
// With custom configuration
export default defineConfig({
integrations: [
mdx({
extendMarkdownConfig: false,
remarkPlugins: [remarkGfm],
rehypePlugins: [rehypeSlug],
optimize: true,
}),
],
});
// With advanced plugin configuration
export default defineConfig({
integrations: [
mdx({
remarkPlugins: [
[remarkToc, { heading: "contents" }],
remarkMath,
],
rehypePlugins: [
[rehypeMathjax, { tex: { displayMath: [["$$", "$$"]] } }],
],
recmaPlugins: [],
}),
],
});Returns the container renderer configuration for MDX components in server contexts.
/**
* Returns container renderer configuration for MDX components
* @returns ContainerRenderer configuration object
*/
export function getContainerRenderer(): ContainerRenderer;
interface ContainerRenderer {
/** Renderer identifier */
name: string;
/** Path to server entrypoint for rendering */
serverEntrypoint: string;
}Usage Example:
import { getContainerRenderer } from "@astrojs/mdx";
// Get renderer configuration
const renderer = getContainerRenderer();
// Returns: { name: 'astro:jsx', serverEntrypoint: '@astrojs/mdx/server.js' }The MDX integration uses two main Astro hooks:
This hook runs during Astro's configuration setup phase and:
.mdx page extension.mdx files in content collectionsThis hook runs after configuration is finalized and:
extendMarkdownConfig optionThe integration automatically configures support for .mdx files in Astro's content collections:
// Automatic content entry type registration
{
extensions: ['.mdx'],
async getEntryInfo({ fileUrl, contents }) {
const parsed = safeParseFrontmatter(contents, fileURLToPath(fileUrl));
return {
data: parsed.frontmatter,
body: parsed.content.trim(),
slug: parsed.frontmatter.slug,
rawData: parsed.rawFrontmatter,
};
},
contentModuleTypes: "...", // TypeScript definitions
handlePropagation: true, // Enable script/style propagation
}This enables using .mdx files in content collections with:
The integration applies these defaults when no options are provided:
const defaultMdxOptions = {
extendMarkdownConfig: true,
recmaPlugins: [],
optimize: false,
};When extendMarkdownConfig is true, the integration inherits configuration from Astro's markdown settings, including: