@@ -483,6 +483,14 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or
483
483
484
484
#### Create React App (CRA)
485
485
486
+ <Note type = " info" >
487
+ ** Note** : rewiring with CRACO (see below) is currently required for CRA 5,
488
+ due to a bug in ` react-scripts `
489
+ ([ ` facebook/create-react-app#12166 ` ] ( https://github.com/facebook/create-react-app/issues/12166 ) ),
490
+ which is also tracked at
491
+ [ ` mdx-js/mdx#1870 ` ] ( https://github.com/mdx-js/mdx/discussions/1870 ) .
492
+ </Note >
493
+
486
494
<details >
487
495
<summary >Expand example</summary >
488
496
@@ -506,7 +514,43 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or
506
514
through webpack loader syntax in imports.
507
515
508
516
Install the webpack loader [ ` @mdx-js/loader ` ] [ mdx-loader ] .
509
- There is no need to configure it.
517
+
518
+ <details >
519
+ <summary >Expand CRACO example</summary >
520
+
521
+ ``` js path="craco.config.js"
522
+ const {addAfterLoader , loaderByName } = require (' @craco/craco' )
523
+
524
+ module .exports = {
525
+ webpack: {
526
+ configure (webpackConfig ) {
527
+ addAfterLoader (webpackConfig, loaderByName (' babel-loader' ), {
528
+ test: / \. mdx? $ / ,
529
+ loader: require .resolve (' @mdx-js/loader' )
530
+ })
531
+ return webpackConfig
532
+ }
533
+ }
534
+ }
535
+ ```
536
+
537
+ ``` jsx path="src/App.jsx"
538
+ import Content from ' ./content.mdx'
539
+
540
+ export default function App () {
541
+ return < Content / >
542
+ }
543
+ ```
544
+ </details >
545
+
546
+ For importing MDX without the ` !@mdx-js/loader! ` prefix, you can add
547
+ the loader to the webpack config, by rewiring ` react-scripts ` using
548
+ [ CRACO] ( http://github.com/gsoft-inc/craco ) .
549
+
550
+ <Note type = " info" >
551
+ ** Note** : warnings about CRACO having `incorrect peer dependency
552
+ "react-scripts@^4.0.0"` can be ignored for the above to work.
553
+ </Note >
510
554
511
555
See also [ ¶ Webpack] [ webpack ] , which is used in CRA, and see [ ¶ React] [ react ] ,
512
556
which you’re likely using, for more info.
1 commit comments
vercel[bot] commentedon May 9, 2022
Successfully deployed to the following URLs:
mdx – ./
mdx-git-main-mdx.vercel.app
mdx-mdx.vercel.app
v2.mdxjs.com
mdxjs.com