Skip to content

umi如何使用mdx #11966

Answered by fz6m
kevinkan000 asked this question in Q&A
Discussion options

You must be logged in to vote
  pnpm add -D @mdx-js/loader
// 项目根目录下创建一个 plugin.ts 文件

import { type IApi } from 'umi'

export default (api: IApi) => {
  api.modifyConfig(async (memo) => {
    const remarkGfm = (await import('remark-gfm')).default

    memo.mdx = {
      loader: '@mdx-js/loader',
      loaderOptions: {
        remarkPlugins: [remarkGfm],
      },
    }
    return memo
  })
}
// index.tsx

import MdxComponent from './path/to/file.mdx'

// ...

<MdxComponent />
// src/global.d.ts

declare module '*.mdx' {
  let MDXComponent: (props: any) => JSX.Element
  export default MDXComponent
}

关于更多配置详见 mdx 官网。

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by xiaohuoni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants