How to add custom component mapping with @mdx-js/loader? #2032
-
I use Next.js so I have a loader like this webpack: (config, options) => {
config.module.rules.push({
test: /\.mdx$/, // no need of .md
use: [
options.defaultLoaders.babel,
{
loader: "@mdx-js/loader",
/** @type {import("@mdx-js/loader").Options} */
options: {},
},
],
});
return config;
} Now I can use MDX files directly as pages just fine. // pages/hello.mdx
// Now I can access it at `/hello`
# Hello world! However, I want to override, say, I think I have missed some documentation section here, but I can't find out or figure out myself how to do that with just a MDX file and the above How should I do that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I don’t understand what you’re asking for. You want to have React components in your webpack config? That’s not where React components go. You found the docs for “custom components mapping” already. The page continues by explaining the optional MDX provider. That are the two ways to do this. There are no other ways. |
Beta Was this translation helpful? Give feedback.
-
MDX components can be injected in Next.js in two ways. Both involve editing
I think typically you’ll want to use the second method. |
Beta Was this translation helpful? Give feedback.
MDX components can be injected in Next.js in two ways. Both involve editing
pages/_app.js
.You can inject the
components
prop into all of your pages. This will make the prop available in all of your pages, including non MDX pages, but not components defined outside of pages.You can insert a
@mdx-js/react
provider and set it as theproviderImportSource
. This will…