Skip to content

Commit fdbf01c

Browse files
committed
Update create-react-app docs to use official library (#359)
* Use mdx.macro for create-react-app example Closes #358 * Update surrounding documentation * Fix linting * Nuke esling config in cra so it doesn't get picked up
1 parent 9e90442 commit fdbf01c

File tree

15 files changed

+4185
-2559
lines changed

15 files changed

+4185
-2559
lines changed
Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
import { Message } from 'rebass'
2-
31
# Create React App
42

5-
<Message>
6-
This docs page is a WIP
7-
</Message>
3+
Please note there’s a [known bug][] with
4+
the macro so live reloading doesn’t
5+
currently work.
86

97
With Create React App you will need to use
10-
[`create-react-app-rewired`][cra-rewired] and add a `config-overrides.js`.
8+
[`mdx.macro`][mdx-macro].
9+
10+
```sh
11+
npx create-react-app my-app
12+
yarn add mdx.macro
13+
```
14+
15+
Then create the following `src/App.js`:
1116

1217
```js
13-
const { getBabelLoader } = require('react-app-rewired')
14-
15-
module.exports = (config, env) => {
16-
const babelLoader = getBabelLoader(config.module.rules)
17-
config.module.rules.map(rule => {
18-
if (typeof rule.test !== 'undefined' || typeof rule.oneOf === 'undefined') {
19-
return rule
20-
}
21-
22-
rule.oneOf.unshift({
23-
test: /\.mdx$/,
24-
use: [
25-
{
26-
loader: babelLoader.loader,
27-
options: babelLoader.options
28-
},
29-
'@mdx-js/loader'
30-
]
31-
})
32-
33-
return rule
34-
})
35-
36-
return config
18+
// src/App.js
19+
20+
import React, { lazy, Component, Suspense } from 'react';
21+
import { importMDX } from 'mdx.macro';
22+
23+
const Content = lazy(() => importMDX('./Content.mdx'));
24+
25+
class App extends Component {
26+
render() {
27+
return (
28+
<div>
29+
<Suspense fallback={<div>Loading...</div>}>
30+
<Content />
31+
</Suspense>
32+
</div>
33+
);
34+
}
3735
}
36+
37+
export default App;
38+
```
39+
40+
And then create the following `src/Content.mdx`:
41+
42+
```md
43+
# Hello, world!
3844
```
3945

4046
[See the full example][cra-example]
4147

42-
[cra-rewired]: https://github.com/timarney/react-app-rewired
48+
[mdx-macro]: https://www.npmjs.com/package/mdx.macro
4349

4450
[cra-example]: https://github.com/mdx-js/mdx/tree/master/examples/create-react-app
51+
52+
[known bug]: https://github.com/facebook/create-react-app/issues/5580

examples/create-react-app/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# See https://help.github.com/ignore-files/ for more about ignoring files.
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
44
/node_modules
5+
/.pnp
6+
.pnp.js
57

68
# testing
79
/coverage

examples/create-react-app/config-overrides.js

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
{
2+
"name": "create-react-app",
3+
"version": "0.1.0",
24
"private": true,
3-
"name": "mdx-create-react-app",
45
"dependencies": {
5-
"@mdx-js/loader": "^0.16.4",
6-
"@mdx-js/mdx": "^0.16.4",
6+
"mdx.macro": "^0.2.7",
77
"react": "^16.6.3",
8-
"react-app-rewired": "^1.6.2",
98
"react-dom": "^16.6.3",
10-
"react-scripts": "1.1.5"
9+
"react-scripts": "2.1.1"
1110
},
1211
"scripts": {
13-
"start": "react-app-rewired start",
14-
"build": "react-app-rewired build",
15-
"test": "react-app-rewired test --env=jsdom"
16-
}
12+
"start": "react-scripts start",
13+
"build": "react-scripts build",
14+
"test": "react-scripts test",
15+
"eject": "react-scripts eject"
16+
},
17+
"browserslist": [
18+
">0.2%",
19+
"not dead",
20+
"not ie <= 11",
21+
"not op_mini all"
22+
]
1723
}

examples/create-react-app/public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
56
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
67
<meta name="theme-color" content="#000000">
78
<!--
89
manifest.json provides metadata used when your web app is added to the
9-
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
10+
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
1011
-->
1112
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
1313
<!--
1414
Notice the use of %PUBLIC_URL% in the tags above.
1515
It will be replaced with the URL of the `public` folder during the build.

examples/create-react-app/public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "image/x-icon"
99
}
1010
],
11-
"start_url": "./index.html",
11+
"start_url": ".",
1212
"display": "standalone",
1313
"theme_color": "#000000",
1414
"background_color": "#ffffff"

examples/create-react-app/readme.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,46 @@
1-
# MDX + Create React App
1+
# Create React App
22

3-
```shell
4-
npm install
5-
npm start
6-
```
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
74

8-
[See documentation](https://mdxjs.com/getting-started/create-react-app)
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.<br>
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.<br>
15+
You will also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.<br>
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.<br>
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.<br>
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).

examples/create-react-app/src/App.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 40vmin;
8+
}
9+
10+
.App-header {
11+
background-color: #282c34;
12+
min-height: 100vh;
13+
display: flex;
14+
flex-direction: column;
15+
align-items: center;
16+
justify-content: center;
17+
font-size: calc(10px + 2vmin);
18+
color: white;
19+
}
20+
21+
.App-link {
22+
color: #61dafb;
23+
}
24+
25+
@keyframes App-logo-spin {
26+
from {
27+
transform: rotate(0deg);
28+
}
29+
to {
30+
transform: rotate(360deg);
31+
}
32+
}

examples/create-react-app/src/App.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import React, {Component} from 'react'
2-
import {MDXProvider} from '@mdx-js/tag'
1+
import React, {lazy, Component, Suspense} from 'react'
2+
import {importMDX} from 'mdx.macro'
33

4-
import Hello from './hello.md'
5-
6-
const components = {
7-
h1: props => <h1 style={{color: 'tomato'}} {...props} />
8-
}
4+
const Content = lazy(() => importMDX('./Content.mdx'))
95

106
class App extends Component {
117
render() {
128
return (
13-
<MDXProvider components={components}>
14-
<Hello />
15-
</MDXProvider>
9+
<div>
10+
<Suspense fallback={<div>Loading...</div>}>
11+
<Content />
12+
</Suspense>
13+
</div>
1614
)
1715
}
1816
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const Demo = () => (
2+
<div style={{ padding: 20, backgroundColor: "tomato" }} />
3+
);
4+
5+
# Hello, world!
6+
7+
<Demo />
8+

examples/create-react-app/src/hello.md

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
6+
sans-serif;
7+
-webkit-font-smoothing: antialiased;
8+
-moz-osx-font-smoothing: grayscale;
9+
}
10+
11+
code {
12+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
13+
monospace;
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
3+
import './index.css'
34
import App from './App'
45

56
ReactDOM.render(<App />, document.getElementById('root'))
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)