Skip to content
MDX logo
v1.6.21

Gatsby

要将 MDX 用于 Gatsby,需要安装 gatsby-plugin-mdx 插件。

首先,创建一个新的 Gatsby 2.0 或更高版本的站点,然后安装 gatsby-plugin-mdx 插件。

gatsby new gatsby-site
cd gatsby-site
yarn add gatsby-plugin-mdx @mdx-js/mdx@latest @mdx-js/react@latest

再添加 gatsby-plugin-mdxgatsby-config.js 配置文件的 plugins 配置段中。

module.exports = {
siteMetadata: {
title: `My Ambitious Project`
},
plugins: [`gatsby-plugin-mdx`]
}

最后,在src/pages 目录下添加一个 .mdx 文件。 看一看是不是 “起作用了”。

# My first MDX Page
some awesome content

有关使用 Gatsby 以编程方式创建页面的文档,请 参阅 Gatsby MDX 文档

Edit this page on GitHub
Previous:
Next.js 集成 MDX
Next:
Create React App 集成 MDX