Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
The withDocsInfra function is a Next.js configuration plugin that sets up webpack loaders, Turbopack rules, and page extensions required for MUI docs infrastructure. It automatically configures code highlighting loaders for demo files and provides sensible defaults for documentation sites.
index.ts and client.ts).md, .mdx, .ts, .tsx, .js, .jsx filesgetDocsInfraMdxOptions for MDX plugin configuration// next.config.mjs
import { withDocsInfra } from '@mui/internal-docs-infra/withDocsInfra';
const nextConfig = {
// Your existing Next.js config
};
export default withDocsInfra()(nextConfig);
// next.config.mjs
import { withDocsInfra, getDocsInfraMdxOptions } from '@mui/internal-docs-infra/withDocsInfra';
import createMDX from '@next/mdx';
const withMDX = createMDX({
options: getDocsInfraMdxOptions({
// Control index generation
extractToIndex: {
include: ['app/docs', 'app/api'],
exclude: ['app/docs/internal'],
},
}),
});
const nextConfig = {
// Your Next.js config
};
export default withDocsInfra({
// Add support for additional file extensions
additionalPageExtensions: ['vue', 'svelte'],
// Disable export output if using server features
enableExportOutput: false,
// Add custom demo patterns beyond the defaults
additionalDemoPatterns: {
index: ['./app/**/demos/*/demo-*/index.ts'],
client: ['./app/**/demos/*/demo-*/client.ts'],
},
// Add custom Turbopack rules
additionalTurbopackRules: {
'./custom/**/*.ts': {
loaders: ['custom-loader'],
},
},
// Comment extraction for sourceEnhancers
// Collect @highlight comments to pass to enhancers
notableCommentsPrefix: ['@highlight', '@focus'],
// Strip @internal comments from displayed source
removeCommentsWithPrefix: ['@internal'],
})(withMDX(nextConfig));
By default, withDocsInfra enables these page extensions:
js, jsx - JavaScript filesmd, mdx - Markdown filests, tsx - TypeScript filesThe plugin automatically configures loaders for these patterns:
Turbopack Rules:
{
'./app/**/demos/*/index.ts': {
loaders: ['@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighter']
},
'./app/**/demos/*/client.ts': {
loaders: ['@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient']
}
}
Webpack Rules:
{
test: /[/\\]demos[/\\][^/\\]+[/\\]index\.ts$/,
use: [
defaultLoaders.babel,
'@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighter'
]
}
Use getDocsInfraMdxOptions to configure MDX with docs-infra plugins:
import { withDocsInfra, getDocsInfraMdxOptions } from '@mui/internal-docs-infra/withDocsInfra';
import createMDX from '@next/mdx';
// Default docs-infra MDX plugins with automatic index generation
const withMDX = createMDX({
options: getDocsInfraMdxOptions(),
});
const nextConfig = {
// Your Next.js config
};
export default withDocsInfra()(withMDX(nextConfig));
// With additional plugins
const withMDX = createMDX({
options: getDocsInfraMdxOptions({
additionalRemarkPlugins: [['remark-emoji']],
additionalRehypePlugins: [['rehype-highlight']],
}),
});
// Custom plugin overrides (replaces all default plugins)
const withMDX = createMDX({
options: getDocsInfraMdxOptions({
remarkPlugins: [['remark-gfm'], ['custom-plugin']],
rehypePlugins: [['custom-rehype-plugin']],
}),
});
The extractToIndex option is passed via getDocsInfraMdxOptions, not withDocsInfra:
// Disable index generation
const withMDX = createMDX({
options: getDocsInfraMdxOptions({
extractToIndex: false,
}),
});
export default withDocsInfra()(withMDX(nextConfig));
// Custom path filters for index generation
const withMDX = createMDX({
options: getDocsInfraMdxOptions({
extractToIndex: {
include: ['app/docs', 'app/api'],
exclude: ['app/docs/internal'],
},
}),
});
export default withDocsInfra()(withMDX(nextConfig));
remark-gfm - GitHub Flavored Markdown supporttransformMarkdownRelativePaths - Convert relative paths for docstransformMarkdownBlockquoteCallouts - Convert blockquotes to calloutstransformMarkdownCode - Process code blockstransformHtmlCode - Transform HTML code elementsIf your demos follow a different pattern (e.g., demo-variant/index.ts):
const nextConfig = withDocsInfra({
additionalDemoPatterns: {
index: ['./app/**/demos/*/demo-*/index.ts'],
client: ['./app/**/demos/*/demo-*/client.ts'],
},
})({});
This will configure loaders for paths like:
./app/components/demos/Button/demo-variant/index.ts./app/components/demos/Button/demo-basic/client.tsComplete Next.js configuration for a docs site:
// next.config.mjs
import { withDocsInfra, getDocsInfraMdxOptions } from '@mui/internal-docs-infra/withDocsInfra';
import createMDX from '@next/mdx';
const withMDX = createMDX({
options: getDocsInfraMdxOptions({
additionalRemarkPlugins: [['remark-emoji']],
}),
});
const nextConfig = {
// Your app-specific config
experimental: {
appDir: true,
},
};
export default withDocsInfra({
additionalDemoPatterns: {
index: ['./app/**/demos/*/demo-*/index.ts'],
client: ['./app/**/demos/*/demo-*/client.ts'],
},
})(withMDX(nextConfig));
By default, the plugin automatically extracts page metadata and maintains parent directory indexes. See examples in Controlling Index Generation above.
The default filter { include: ['app', 'src/app'], exclude: [] } processes all pages in both app/ and src/app/ directories (without trailing slashes - they're added automatically during matching). Index files (e.g., app/page.mdx, app/components/page.mdx) are automatically excluded to prevent them from creating parent indexes. The base directory is automatically detected from process.cwd().
For complete details, see the transformMarkdownMetadata documentation.
withDocsInfraNext.js plugin for MUI docs infrastructure. Configures webpack loaders, turbopack rules for docs sites. Use getDocsInfraMdxOptions() with createMDX for MDX integration.
| Parameter | Type | Description |
|---|---|---|
| options | WithDocsInfraOptions | undefined |
((nextConfig?: NextConfig) => NextConfig)getDocsInfraMdxOptionsGet default MDX options for docs-infra
| Parameter | Type | Description |
|---|---|---|
| customOptions | DocsInfraMdxOptions | undefined |
| Key | Type | Description |
|---|---|---|
| remarkPlugins | (string | [string, any])[] | undefined | |
| rehypePlugins | (string | [string, any])[] | undefined | |
| additionalRemarkPlugins | (string | [string, any])[] | undefined | Additional remark plugins to add to the default docs-infra plugins |
| additionalRehypePlugins | (string | [string, any])[] | undefined | Additional rehype plugins to add to the default docs-infra plugins |
| extractToIndex | | Whether to automatically extract page metadata (title, description, headings) from MDX files and maintain an index in the parent directory’s page.mdx file. Index files themselves (e.g., pattern/page.mdx) are automatically excluded from extraction. Can be:
|
| baseDir | string | undefined | Base directory for path filtering. Defaults to process.cwd(). Only needed when calling the plugin directly (not via withDocsInfra). |
| errorIfIndexOutOfDate | boolean | undefined | Throw an error if any index is out of date or missing. Useful for CI environments to ensure indexes are committed. |
| defaultInlineCodeLanguage | string | false | undefined | Default language for inline code syntax highlighting.
Set to |
withDeploymentConfig| Parameter | Type | Description |
|---|---|---|
| nextConfig | NextConfig |
NextConfigtype DocsInfraMdxOptions = {
remarkPlugins?: (string | [string, any])[];
rehypePlugins?: (string | [string, any])[];
additionalRemarkPlugins?: (string | [string, any])[];
additionalRehypePlugins?: (string | [string, any])[];
extractToIndex?: boolean | { include: string[]; exclude: string[] };
baseDir?: string;
errorIfIndexOutOfDate?: boolean;
defaultInlineCodeLanguage?: string | false;
};type WebpackOptions = {
buildId: string;
dev: boolean;
isServer: boolean;
nextRuntime?: 'nodejs' | 'edge';
config: NextConfig;
defaultLoaders: { babel: RuleSetRule };
};type WithDocsInfraOptions = {
additionalPageExtensions?: string[];
enableExportOutput?: boolean;
demoPathPattern?: string;
clientDemoPathPattern?: string;
additionalDemoPatterns?: { index?: string[]; client?: string[] };
additionalTurbopackRules?: Record<string, { loaders: string[] }>;
performance?: { logging: boolean; notableMs?: number; showWrapperMeasures?: boolean };
deferCodeParsing?: 'gzip' | 'json' | 'none';
removeCommentsWithPrefix?: string[];
notableCommentsPrefix?: string[];
typesIndexFileName?: string;
errorIfTypesIndexOutOfDate?: boolean;
};loadPrecomputedCodeHighlighterClient - Loader for demo client filesCodeHighlighter - Component that renders highlighted demos