mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: support Vite 8 moduleType option
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
support Vite 8 `moduleType` option
|
||||
@@ -22,6 +22,13 @@ export interface LoaderInput {
|
||||
export interface LoaderOutput {
|
||||
code: string;
|
||||
map?: unknown;
|
||||
|
||||
/**
|
||||
* Only supported in Vite 8.
|
||||
*
|
||||
* Explicitly define the transformed module type, for unsupported environments, you need to consider the differences between each bundler.
|
||||
*/
|
||||
moduleType?: 'js' | 'json';
|
||||
}
|
||||
|
||||
type Awaitable<T> = T | Promise<T>;
|
||||
@@ -119,6 +126,7 @@ export function toVite(loader: Loader): ViteLoader {
|
||||
return {
|
||||
code: result.code,
|
||||
map: result.map as SourceMap,
|
||||
moduleType: result.moduleType,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -172,7 +180,7 @@ export function toBun(loader: Loader) {
|
||||
|
||||
return {
|
||||
contents: output.code,
|
||||
loader: 'js',
|
||||
loader: output.moduleType ?? 'js',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Loader, LoaderInput } from '@/loaders/adapter';
|
||||
import type { ConfigLoader } from '@/loaders/config';
|
||||
import { dump, load } from 'js-yaml';
|
||||
import { load } from 'js-yaml';
|
||||
import { z } from 'zod';
|
||||
import { metaLoaderGlob } from '.';
|
||||
import type { MetaCollectionItem } from '@/config/build';
|
||||
@@ -19,10 +19,10 @@ export function createMetaLoader(
|
||||
{ getCore }: ConfigLoader,
|
||||
resolve: {
|
||||
json?: 'json' | 'js';
|
||||
yaml?: 'yaml' | 'js';
|
||||
yaml?: 'js';
|
||||
} = {},
|
||||
): Loader {
|
||||
const { json: resolveJson = 'js', yaml: resolveYaml = 'js' } = resolve;
|
||||
const { json: resolveJson = 'js' } = resolve;
|
||||
|
||||
function parse(filePath: string, source: string) {
|
||||
try {
|
||||
@@ -81,6 +81,7 @@ export function createMetaLoader(
|
||||
|
||||
if (input.filePath.endsWith('.json')) {
|
||||
return {
|
||||
moduleType: resolveJson,
|
||||
code:
|
||||
resolveJson === 'json'
|
||||
? JSON.stringify(data)
|
||||
@@ -88,10 +89,8 @@ export function createMetaLoader(
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code:
|
||||
resolveYaml === 'yaml'
|
||||
? dump(data)
|
||||
: `export default ${JSON.stringify(data)}`,
|
||||
moduleType: 'js',
|
||||
code: `export default ${JSON.stringify(data)}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user