Getting Started with MDX
The fastest way to get started with Gatsby + MDX is to use the MDX
starter. This
allows you to write .mdx files in src/pages in order to create new pages on
your site.
🚀 Quick start
Initialize the MDX starter with the Gatsby CLI
Run the dev server by changing directory to the scaffolded site and install dependencies
Open the site running at http://localhost:8000
Update the MDX content by opening the
my-mdx-starterdirectory in your code editor of choice and editsrc/pages/index.mdx. Save your changes and the browser will update in real time!
Add MDX to an existing Gatsby site
If you already have a Gatsby site that you’d like to add MDX to, you can follow these steps for configuring the gatsby-plugin-mdx plugin:
Add
gatsby-plugin-mdxand MDX as dependenciesNote: If you’re upgrading from v0, additionally check out the MDX migration guide.
Update your
gatsby-config.jsto usegatsby-plugin-mdxRestart
gatsby developand add an.mdxpage to `src/pages
Note: If you want to query for frontmatter, exports, or other fields like
tableOfContentsand you haven’t previously added agatsby-source-filesystempointing atsrc/pagesin your project, you’ll want to add one now.
What’s next?
Go check out the writing MDX guide to find out what else you can do with Gatsby and MDX.
Edit this page on GitHub