@@ -549,7 +549,7 @@ the loader to the webpack config, by rewiring `react-scripts` using
549549
550550<Note type = " info" >
551551 ** Note** : warnings about CRACO having `incorrect peer dependency
552- "react-scripts@^4.0.0"` can be ignored for the above to work.
552+ "react-scripts@^4.0.0"` can be ignored for the above to work.
553553</Note >
554554
555555See also [ ¶ Webpack] [ webpack ] , which is used in CRA, and see [ ¶ React] [ react ] ,
@@ -573,40 +573,67 @@ on how to use MDX with Gatsby.
573573 <summary >Expand example</summary >
574574
575575 ``` js path="next.config.js"
576- module .exports = {
577- // Prefer loading of ES Modules over CommonJS
578- experimental: {esmExternals: true },
576+ import nextMDX from ' @next/mdx'
577+
578+ const withMDX = nextMDX ({
579+ // By default only the .mdx extension is supported.
580+ extension: / \. mdx? $ / ,
581+ options: {/* providerImportSource: …, otherOptions… */ }
582+ })
583+
584+ export default withMDX ({
579585 // Support MDX files as pages:
580586 pageExtensions: [' md' , ' mdx' , ' tsx' , ' ts' , ' jsx' , ' js' ],
581- // Support loading `.md`, `.mdx`:
582- webpack (config , options ) {
583- config .module .rules .push ({
584- test: / \. mdx? $ / ,
585- use: [
586- // The default `babel-loader` used by Next:
587- options .defaultLoaders .babel ,
588- {
589- loader: ' @mdx-js/loader' ,
590- /** @type {import('@mdx-js/loader').Options} */
591- options: {/* jsxImportSource: …, otherOptions… */ }
592- }
593- ]
594- })
595-
596- return config
597- }
598- }
587+ })
599588 ```
600589</details >
601590
602- [ Next] ( https://nextjs.org ) supports webpack loaders by overwriting the webpack
603- config in ` next.config.js ` .
591+ [ Next.js] ( https://nextjs.org ) has its own package to support MDX.
604592
605- Install and configure the webpack loader [ ` @mdx-js/loader ` ] [ webpack ] .
593+ Install and configure [ ` @next/mdx ` ] [ @next/mdx ] .
606594There is no need to configure your JSX runtime as React is already set up.
607595
608- See also [ ¶ Webpack] [ webpack ] and [ ¶ React] [ react ] , which you’re using, for
609- more on those tools.
596+ The MDX provider can be configured in [ ` pages/_app.js ` ] [ next-app ] .
597+ In order to use it, you need to configure the ` providerImportSource ` as
598+ well.
599+
600+ <details >
601+ <summary >Expand example</summary >
602+
603+ ``` js path="next.config.js"
604+ import nextMDX from ' @next/mdx'
605+
606+ const withMDX = nextMDX ({
607+ // By default only the .mdx extension is supported.
608+ extension: / \. mdx? $ / ,
609+ options: {providerImportSource: ' @mdx-js/react' , /* otherOptions… */ }
610+ })
611+
612+ export default withMDX ({
613+ // Support MDX files as pages:
614+ pageExtensions: [' md' , ' mdx' , ' tsx' , ' ts' , ' jsx' , ' js' ],
615+ })
616+ ```
617+
618+ ``` jsx path="pages/_app.js"
619+ import {MDXProvider } from ' @mdx-js/react'
620+ import {Header } from ' ../components/Header.js'
621+
622+ const components = {
623+ h1: Header
624+ }
625+
626+ export default function App ({Component, pageProps}) {
627+ return (
628+ < MDXProvider components= {components}>
629+ < Component {... pageProps} / >
630+ < / MDXProvider>
631+ )
632+ }
633+ ```
634+ </details >
635+
636+ See [ Using MDX with Next.js] [ next-mdx ] for more details.
610637
611638#### Parcel
612639
@@ -842,6 +869,8 @@ See their readmes on how to configure them.
842869* If you’re getting errors integrating MDX, see
843870 [ § Troubleshooting MDX] [ trouble ] or [ § Support] [ support ]
844871
872+ [ @next/mdx ] : https://github.com/vercel/next.js/tree/canary/packages/next-mdx
873+
845874[ svelte-jsx ] : https://github.com/kenoxa/svelte-jsx
846875
847876[ jsx ] : #jsx
@@ -874,6 +903,10 @@ See their readmes on how to configure them.
874903
875904[ mdx-vue ] : /packages/vue/
876905
906+ [ next-app ] : https://nextjs.org/docs/advanced-features/custom-app
907+
908+ [ next-mdx ] : https://nextjs.org/docs/advanced-features/using-mdx
909+
877910[ evaluate ] : /packages/mdx/#evaluatefile-options
878911
879912[ options-jsximportsource ] : /packages/mdx/#optionsjsximportsource
0 commit comments