diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index c2e517b9b..c4d8088a9 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -1,4 +1,5 @@ import type { AstroIntegration } from 'astro'; +import type { InlineConfig } from 'vite'; export default function markdoc(partialOptions: {} = {}): AstroIntegration { return { @@ -7,6 +8,19 @@ export default function markdoc(partialOptions: {} = {}): AstroIntegration { 'astro:config:setup': async ({ updateConfig, config, addPageExtension, command }: any) => { addPageExtension('.mdoc'); console.log('Markdoc working!'); + + const viteConfig: InlineConfig = { + plugins: [ + { + name: '@astrojs/markdoc', + async transform(code, id) { + if (!id.endsWith('.mdoc')) return; + return `export const body = ${JSON.stringify(code)}`; + }, + }, + ], + }; + updateConfig({ vite: viteConfig }); }, }, };