Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improved getting started for current CRA 5 integration #2010

Merged
merged 1 commit into from May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 45 additions & 1 deletion docs/docs/getting-started.server.mdx
Expand Up @@ -483,6 +483,14 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or

#### Create React App (CRA)

<Note type="info">
**Note**: rewiring with CRACO (see below) is currently required for CRA 5,
due to a bug in `react-scripts`
([`facebook/create-react-app#12166`](https://github.com/facebook/create-react-app/issues/12166)),
which is also tracked at
[`mdx-js/mdx#1870`](https://github.com/mdx-js/mdx/discussions/1870).
</Note>

<details>
<summary>Expand example</summary>

Expand All @@ -506,7 +514,43 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or
through webpack loader syntax in imports.

Install the webpack loader [`@mdx-js/loader`][mdx-loader].
There is no need to configure it.

<details>
<summary>Expand CRACO example</summary>

```js path="craco.config.js"
const {addAfterLoader, loaderByName} = require('@craco/craco')

module.exports = {
webpack: {
configure(webpackConfig) {
addAfterLoader(webpackConfig, loaderByName('babel-loader'), {
test: /\.mdx?$/,
loader: require.resolve('@mdx-js/loader')
})
return webpackConfig
}
}
}
```

```jsx path="src/App.jsx"
import Content from './content.mdx'

export default function App() {
return <Content />
}
```
</details>

For importing MDX without the `!@mdx-js/loader!` prefix, you can add
the loader to the webpack config, by rewiring `react-scripts` using
[CRACO](http://github.com/gsoft-inc/craco).

<Note type="info">
**Note**: warnings about CRACO having `incorrect peer dependency
"react-scripts@^4.0.0"` can be ignored for the above to work.
</Note>

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