Skip to content

Is it possible to compile and bundle an MDX string on the client side? #2220

Discussion options

You must be logged in to vote

Welcome @guilherme-marin! 👋

Is it possible to compile and bundle an MDX string on the client side?

Yes, but multiple tools are needed.
MDX will compile MDX text to JS text, then you could run WebPack, Rollup, or another bundler in browser to bundle that code up.

Though, it appears your end goal is a preview of how the content is rendered?

I'm trying to create something similar to this (contextual editor from Tina`s CMS)

For that, you may not need to bundle.
mdx.evaluate() or mdx.evaluateSync() could be used https://mdxjs.com/packages/mdx/#evaluatefile-options
It will pass back a React component you can add to the page, and as an alternative to bundling you can pass custom elements/com…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@LukasBombach
Comment options

@CooperHash
Comment options

@ChristianMurphy
Comment options

@CooperHash
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
4 participants