Is it possible to compile and bundle an MDX string on the client side? #2220
-
👋 Hello there! Noob question over here... I'm trying to create something similar to this (contextual editor from Tina`s CMS) with NextJS and bundler-mdx: What I've done so far is related to building the MDX string on the client side (I understand the risks), going through the AST and inserting new nodes, changing the frontmatter and referencing imports when a new custom component is embedded. This works so far, the result is an MDX string inside a state, but I am not able to compile and bundle this MDX string again, I'm tryng to render a preview of the changes on client side. I'm looking for some guidance on this as I don't know if I'm on the right track. Is there a reasonable way to do this on client side, preferably without having to access the server side every time a change is made? How? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Welcome @guilherme-marin! 👋
Yes, but multiple tools are needed. Though, it appears your end goal is a preview of how the content is rendered?
For that, you may not need to bundle. |
Beta Was this translation helpful? Give feedback.
Welcome @guilherme-marin! 👋
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?
For that, you may not need to bundle.
mdx.evaluate()
ormdx.evaluateSync()
could be used https://mdxjs.com/packages/mdx/#evaluatefile-optionsIt will pass back a React component you can add to the page, and as an alternative to bundling you can pass custom elements/com…