Skip to content

Commit

Permalink
docs: Describe current issue w/CRA 5 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
userzimmermann committed Apr 9, 2022
1 parent 4e7046a commit 9d89490
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/docs/getting-started.server.mdx
Expand Up @@ -508,6 +508,47 @@ through webpack loader syntax in imports.
Install the webpack loader [`@mdx-js/loader`][mdx-loader].
There is no need to configure it.

However, to avoid the [ESLint](http://eslint.org)-unfriendly
`!@mdx-js/loader!` import prefix, the loader can be added to webpack’s config,
using a [`react-scripts`](http://github.com/facebook/create-react-app/tree/main/packages/react-scripts)
rewiring tool, like [CRACO](http://github.com/gsoft-inc/craco).

<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: /\.(md|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>

<Note type="info">
**Note**: due to [broken MDX import forwarding](http://github.com/facebook/create-react-app/issues/12166)
in `react-scripts` 5.x, rewiring is currently the most viable option when
using CRA 5. There’s an [ongoing discussion](http://github.com/mdx-js/mdx/discussions/1870)
about this issue.
</Note>

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

Expand Down

0 comments on commit 9d89490

Please sign in to comment.