Skip to content

How to import an mdx file that's at a remote location like S3/Cloudfront URL? #1990

Answered by xHomu
aakanshaverma11 asked this question in Q&A
Discussion options

You must be logged in to vote

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 />

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
3 replies
@aakanshaverma11
Comment options

@xHomu
Comment options

@aakanshaverma11
Comment options

Comment options

You must be logged in to vote
5 replies
@aakanshaverma11
Comment options

@xHomu
Comment options

@aakanshaverma11
Comment options

@aakanshaverma11
Comment options

@ChristianMurphy
Comment options

Answer selected by ChristianMurphy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants