@@ -549,7 +549,7 @@ the loader to the webpack config, by rewiring `react-scripts` using
549
549
550
550
<Note type = " info" >
551
551
** 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.
553
553
</Note >
554
554
555
555
See also [ ¶ Webpack] [ webpack ] , which is used in CRA, and see [ ¶ React] [ react ] ,
@@ -573,40 +573,67 @@ on how to use MDX with Gatsby.
573
573
<summary >Expand example</summary >
574
574
575
575
``` 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 ({
579
585
// Support MDX files as pages:
580
586
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
+ })
599
588
```
600
589
</details >
601
590
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.
604
592
605
- Install and configure the webpack loader [ ` @mdx-js/loader ` ] [ webpack ] .
593
+ Install and configure [ ` @next/mdx ` ] [ @next/mdx ] .
606
594
There is no need to configure your JSX runtime as React is already set up.
607
595
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.
610
637
611
638
#### Parcel
612
639
@@ -842,6 +869,8 @@ See their readmes on how to configure them.
842
869
* If you’re getting errors integrating MDX, see
843
870
[ § Troubleshooting MDX] [ trouble ] or [ § Support] [ support ]
844
871
872
+ [ @next/mdx ] : https://github.com/vercel/next.js/tree/canary/packages/next-mdx
873
+
845
874
[ svelte-jsx ] : https://github.com/kenoxa/svelte-jsx
846
875
847
876
[ jsx ] : #jsx
@@ -874,6 +903,10 @@ See their readmes on how to configure them.
874
903
875
904
[ mdx-vue ] : /packages/vue/
876
905
906
+ [ next-app ] : https://nextjs.org/docs/advanced-features/custom-app
907
+
908
+ [ next-mdx ] : https://nextjs.org/docs/advanced-features/using-mdx
909
+
877
910
[ evaluate ] : /packages/mdx/#evaluatefile-options
878
911
879
912
[ options-jsximportsource ] : /packages/mdx/#optionsjsximportsource
1 commit comments
vercel[bot] commentedon May 15, 2022
Successfully deployed to the following URLs:
mdx – ./
mdx-mdx.vercel.app
mdxjs.com
mdx-git-main-mdx.vercel.app
v2.mdxjs.com