How to import an mdx file that's at a remote location like S3/Cloudfront URL? #1990
-
I want to import the mdx files from a remote location(S3 bucket/Cloudfront URL in my case) but don't know how this import syntax will support a https url |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Use MDX remote https://github.com/hashicorp/next-mdx-remote |
Beta Was this translation helpful? Give feedback.
-
If you're on next, try mdx-next-remote https://github.com/hashicorp/next-mdx-remote Otherwise, try mdx-bundle https://github.com/kentcdodds/mdx-bundler If you need everything done client-side, you can use evaluate or evaluateSync. https://mdxjs.com/packages/mdx/#evaluatesyncfile-options The minimum code would be something like import {evaluateSync} from '@mdx-js/evaluate'
import * as runtime from 'react/jsx-runtime'
//const mdxString is fetched from your remote somehow
const {default: Content} = await evaluateSync(mdxString, {...runtime, useDynamicImport: true});
return <Content /> |
Beta Was this translation helpful? Give feedback.
If you're on next, try mdx-next-remote https://github.com/hashicorp/next-mdx-remote
Otherwise, try mdx-bundle https://github.com/kentcdodds/mdx-bundler
If you need everything done client-side, you can use evaluate or evaluateSync. https://mdxjs.com/packages/mdx/#evaluatesyncfile-options
The minimum code would be something like