UNPKG

fumadocs-mdx

Version:

The built-in source for Fumadocs

87 lines (85 loc) 2.75 kB
import "../fuma-matter-CHgJa_-B.js"; import { t as createMdxLoader } from "../mdx-CPnL-Edm.js"; import "../preset-gmDZnBcg.js"; import { t as buildConfig } from "../build-BTTNEFmV.js"; import { n as createCore, r as ValidationError, t as _Defaults } from "../core-DjldE3H9.js"; import "../codegen-DleOVLNr.js"; import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-DI4cexsC.js"; import { t as createMetaLoader } from "../meta-BKBx8Gab.js"; import { t as indexFile } from "../index-file-D9HsrWU_.js"; import { mergeConfig } from "vite"; //#region src/vite/index.ts async function mdx(config, pluginOptions = {}) { const options = applyDefaults(pluginOptions); const core = createViteCore(options); await core.init({ config: buildConfig(config) }); const configLoader = createIntegratedConfigLoader(core); const mdxLoader = toVite(createMdxLoader(configLoader)); const metaLoader = toVite(createMetaLoader(configLoader, { json: "json" })); return { name: "fumadocs-mdx", enforce: "pre", config(config$1) { if (!options.updateViteConfig) return config$1; return mergeConfig(config$1, { resolve: { noExternal: [ "fumadocs-core", "fumadocs-ui", "fumadocs-openapi", "@fumadocs/base-ui", "@fumadocs/ui" ], dedupe: [ "fumadocs-core", "fumadocs-ui", "fumadocs-openapi", "@fumadocs/base-ui" ] } }); }, async buildStart() { await core.emit({ write: true }); }, async configureServer(server) { await core.initServer({ watcher: server.watcher }); }, async transform(value, id) { try { if (metaLoader.filter(id)) return await metaLoader.transform.call(this, value, id); if (mdxLoader.filter(id)) return await mdxLoader.transform.call(this, value, id); } catch (e) { if (e instanceof ValidationError) throw new Error(await e.toStringFormatted()); throw e; } } }; } async function postInstall(pluginOptions = {}) { const { loadConfig } = await import("../load-from-file-B7Rswy9i.js"); const core = createViteCore(applyDefaults(pluginOptions)); await core.init({ config: loadConfig(core, true) }); await core.emit({ write: true }); } function createViteCore({ index, configPath, outDir }) { if (index === true) index = {}; return createCore({ environment: "vite", configPath, outDir, plugins: [index && indexFile({ ...index, target: index.target ?? "vite" })] }); } function applyDefaults(options) { return { updateViteConfig: options.updateViteConfig ?? true, index: options.index ?? true, configPath: options.configPath ?? _Defaults.configPath, outDir: options.outDir ?? _Defaults.outDir }; } //#endregion export { mdx as default, postInstall }; //# sourceMappingURL=index.js.map