mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: Generate config based on Next.js version
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Generate config based on Next.js version
|
||||
@@ -3,6 +3,8 @@ import type { Configuration } from 'webpack';
|
||||
import { findConfigFile } from '@/utils/config';
|
||||
import { start } from '@/map';
|
||||
import { type Options as MDXLoaderOptions } from '../loader-mdx';
|
||||
import { version } from 'next/package.json';
|
||||
import type { TurbopackOptions } from 'next/dist/server/config-shared';
|
||||
|
||||
export interface CreateMDXOptions {
|
||||
/**
|
||||
@@ -19,6 +21,10 @@ export interface CreateMDXOptions {
|
||||
}
|
||||
|
||||
const defaultPageExtensions = ['mdx', 'md', 'jsx', 'js', 'tsx', 'ts'];
|
||||
const isTurboExperimental =
|
||||
version.startsWith('15.0.') ||
|
||||
version.startsWith('15.1.') ||
|
||||
version.startsWith('15.2.');
|
||||
|
||||
export { start };
|
||||
|
||||
@@ -43,25 +49,26 @@ export function createMDX({
|
||||
configPath,
|
||||
outDir,
|
||||
};
|
||||
|
||||
return {
|
||||
...nextConfig,
|
||||
turbopack: {
|
||||
...nextConfig?.turbopack,
|
||||
rules: {
|
||||
...nextConfig?.turbopack?.rules,
|
||||
// @ts-expect-error -- safe
|
||||
'*.{md,mdx}': {
|
||||
loaders: [
|
||||
{
|
||||
loader: 'fumadocs-mdx/loader-mdx',
|
||||
options: mdxLoaderOptions,
|
||||
},
|
||||
],
|
||||
as: '*.js',
|
||||
},
|
||||
const turbo: TurbopackOptions = {
|
||||
...nextConfig.experimental?.turbo,
|
||||
...nextConfig.turbopack,
|
||||
rules: {
|
||||
...nextConfig.experimental?.turbo?.rules,
|
||||
...nextConfig.turbopack?.rules,
|
||||
'*.{md,mdx}': {
|
||||
loaders: [
|
||||
{
|
||||
loader: 'fumadocs-mdx/loader-mdx',
|
||||
options: mdxLoaderOptions as any,
|
||||
},
|
||||
],
|
||||
as: '*.js',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const updated: NextConfig = {
|
||||
...nextConfig,
|
||||
pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
|
||||
webpack: (config: Configuration, options) => {
|
||||
config.resolve ||= {};
|
||||
@@ -85,5 +92,13 @@ export function createMDX({
|
||||
return nextConfig.webpack?.(config, options) ?? config;
|
||||
},
|
||||
};
|
||||
|
||||
if (isTurboExperimental) {
|
||||
updated.experimental = { ...updated.experimental, turbo };
|
||||
} else {
|
||||
updated.turbopack = turbo;
|
||||
}
|
||||
|
||||
return updated;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user