diff --git a/docs/getting-started/create-react-app.md b/docs/getting-started/create-react-app.md index 28c34c77a..e0f8229ed 100644 --- a/docs/getting-started/create-react-app.md +++ b/docs/getting-started/create-react-app.md @@ -1,15 +1,37 @@ # Create React App -Please note there’s a [known bug][] with -the macro so live reloading doesn’t -currently work. - With Create React App you will need to use -[`mdx.macro`][mdx-macro]. +[`mdx-loader`][mdx-loader]. ```sh npx create-react-app my-app -yarn add mdx.macro +yarn add mdx-loader --dev +``` + +Then create a `.babelrc` file in the root level of your project with the following contents: + +``` +{ + "presets": ["babel-preset-react-app"] +} +``` + +Then, you can import a component from any Markdown file by prepending the filename with `!babel-loader!mdx-loader!`. For example: + +``` +/* eslint-disable import/no-webpack-loader-syntax */ +import MyDocument from '!babel-loader!mdx-loader!../pages/index.md' +``` + +Create a markdown document `src/document.mdx` + +```mdx +--- +title: My Document +--- + +This is **markdown** with JSX! + ``` Then create the following `src/App.js`: @@ -17,18 +39,16 @@ Then create the following `src/App.js`: ```js // src/App.js -import React, { lazy, Component, Suspense } from 'react'; -import { importMDX } from 'mdx.macro'; - -const Content = lazy(() => importMDX('./Content.mdx')); - +import React, { Component } from 'react' +/* eslint-disable import/no-webpack-loader-syntax */ +import Document, { frontMatter, tableOfContents } from '!babel-loader!mdx-loader!./document.mdx' + class App extends Component { render() { return (
- Loading...
}> - - +

{frontMatter.title}

+ ); } @@ -37,16 +57,8 @@ class App extends Component { export default App; ``` -And then create the following `src/Content.mdx`: - -```md -# Hello, world! -``` - [See the full example][cra-example] -[mdx-macro]: https://www.npmjs.com/package/mdx.macro +[mdx-loader]: https://www.npmjs.com/package/mdx-loader [cra-example]: https://github.com/mdx-js/mdx/tree/master/examples/create-react-app - -[known bug]: https://github.com/facebook/create-react-app/issues/5580 diff --git a/examples/create-react-app/package.json b/examples/create-react-app/package.json index f8cb33a52..549631898 100644 --- a/examples/create-react-app/package.json +++ b/examples/create-react-app/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "mdx.macro": "^0.2.8", + "mdx-loader": "^3.0.0", "react": "^16.8.4", "react-dom": "^16.8.4", "react-scripts": "2.1.8" diff --git a/examples/create-react-app/src/.babelrc b/examples/create-react-app/src/.babelrc new file mode 100644 index 000000000..c23d70a5b --- /dev/null +++ b/examples/create-react-app/src/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["babel-preset-react-app"] +} \ No newline at end of file diff --git a/examples/create-react-app/src/App.js b/examples/create-react-app/src/App.js index af7f34838..25e642f4c 100644 --- a/examples/create-react-app/src/App.js +++ b/examples/create-react-app/src/App.js @@ -1,18 +1,18 @@ -import React, {lazy, Component, Suspense} from 'react' -import {importMDX} from 'mdx.macro' - -const Content = lazy(() => importMDX('./Content.mdx')) - +import React, { Component } from 'react' +/* eslint-disable import/no-webpack-loader-syntax */ +import Content, { frontMatter } from '!babel-loader!mdx-loader!./Content.mdx' + class App extends Component { + render() { return (
- Loading...
}> - - +

{frontMatter.title}

+ +

Table of Contents

- ) + ); } } -export default App +export default App; diff --git a/examples/create-react-app/src/Content.mdx b/examples/create-react-app/src/Content.mdx index c6994970b..019b6531d 100644 --- a/examples/create-react-app/src/Content.mdx +++ b/examples/create-react-app/src/Content.mdx @@ -1,8 +1,11 @@ +--- +title: My Content +--- + export const Demo = () => (
); -# Hello, world! - - +This is **markdown** with JSX! + \ No newline at end of file