Skip to content

Commit 7f9a5f4

Browse files
authoredMay 9, 2022
Add improved getting started for current CRA 5 integration
Closes GH-2004. Closes GH-2010. Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent 3c51a43 commit 7f9a5f4

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed
 

‎docs/docs/getting-started.server.mdx

+45-1
Original file line numberDiff line numberDiff line change
@@ -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
506514
through webpack loader syntax in imports.
507515

508516
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>
510554

511555
See also [¶ Webpack][webpack], which is used in CRA, and see [¶ React][react],
512556
which you’re likely using, for more info.

1 commit comments

Comments
 (1)

vercel[bot] commented on May 9, 2022

@vercel[bot]

Successfully deployed to the following URLs:

mdx – ./

mdx-git-main-mdx.vercel.app
mdx-mdx.vercel.app
v2.mdxjs.com
mdxjs.com

Please sign in to comment.