In building out this beautiful website, and the equally beautiful tamagui.dev, the surprising
most difficult part was getting MDX to work well.
Since many blogs, apps, and documentation sites want to display Markdown content, we figure a guide showing how
we did it will be useful.
We think long-term someone should write a much better mdx package, as ours is simply pieced together from a bunch of packages and code we ported long ago to Next.js, but nonetheless it works. It uses a hodge-podge of Rehype plugins to do the trick, alongside mdx-bundler.
The first step is to create a directory for your mdx files to live:
data
hello-world.mdx
Your MDX content goes here
Throw some stuff in that file:
Terminal
---
title: MDX Guide
description: Setting up MDX for web
---
In building out this beautiful website, and the equally beautiful [tamagui.dev](https://tamagui.dev), the surprising
most difficult part was getting MDX to work well...
Note that we await import the @vxrn/mdx library - this is because One by default builds out your server
and API routes to CommonJS, but some of the rehype/remak dependencies are ESM. Long story short - this makes it work.
To ensure that MDX works correctly with your One project, you'll need to configure Vite. Update your vite.config.ts file with the following content:
vite.config.ts
import{ defineConfig }from'vite'
import{ one }from'one/vite'
exportdefaultdefineConfig({
ssr:{
noExternal:true,
external:['@vxrn/mdx'],
},
plugins:[
one({
web:{
defaultRenderMode:'ssg',
},
}),
],
})
This configuration does a few important things:
It sets noExternal: true in the SSR options, which tells Vite to bundle all dependencies for server-side rendering.
It explicitly marks @vxrn/mdx as an external dependency, which is necessary because it contains ESM modules that shouldn't be bundled.
wwwwwwwwwwwwwwwwwww
That should do it. We say should, because there's a lot going on here, and many sub-deps inside @vxrn/mdx that need to work together. Let us know if this works for you!