diff options
Diffstat (limited to 'packages/integrations/mdx/src/index.ts')
-rw-r--r-- | packages/integrations/mdx/src/index.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts new file mode 100644 index 000000000..d07913ede --- /dev/null +++ b/packages/integrations/mdx/src/index.ts @@ -0,0 +1,39 @@ +import type { AstroIntegration } from 'astro'; +import mdxPlugin from '@mdx-js/rollup'; + +export default function mdx(): AstroIntegration { + return { + name: '@astrojs/mdx', + hooks: { + 'astro:config:setup': ({ updateConfig, addPageExtension, command }: any) => { + addPageExtension('.mdx'); + updateConfig({ + vite: { + plugins: [ + { + enforce: 'pre', + ...mdxPlugin({ + jsx: true, + jsxImportSource: 'astro', + // Note: disable `.md` support + format: 'mdx', + mdExtensions: [] + }) + }, + command === 'dev' && { + name: '@astrojs/mdx', + transform(code: string, id: string) { + if (!id.endsWith('.mdx')) return; + // TODO: decline HMR updates until we have a stable approach + return `${code}\nif (import.meta.hot) { + import.meta.hot.decline(); + }` + } + } + ] + } + }) + } + } + } +} |