From 5315c507097c2ccf0f6ca6cc3d73495adfe3e7f8 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 6 Feb 2023 11:21:17 -0500 Subject: [PATCH] feat: get markdoc contents --- packages/integrations/markdoc/src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 }); }, }, };