@@ -483,6 +483,14 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or
483483
484484#### Create React App (CRA)
485485
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+
486494<details >
487495 <summary >Expand example</summary >
488496
@@ -506,7 +514,43 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or
506514through webpack loader syntax in imports.
507515
508516Install 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 >
510554
511555See also [ ¶ Webpack] [ webpack ] , which is used in CRA, and see [ ¶ React] [ react ] ,
512556which you’re likely using, for more info.
0 commit comments