Skip to content

Commit 1682149

Browse files
committed
Use mdx.macro for create-react-app example
Closes #358
1 parent 3bd75e1 commit 1682149

16 files changed

+4301
-2541
lines changed

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: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
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+
"eslintConfig": {
18+
"extends": "react-app"
19+
},
20+
"browserslist": [
21+
">0.2%",
22+
"not dead",
23+
"not ie <= 11",
24+
"not op_mini all"
25+
]
1726
}

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: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1-
# MDX + Create React App
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
22

3-
```shell
4-
npm install
5-
npm start
6-
```
3+
## Available Scripts
74

8-
[See documentation](https://mdxjs.com/getting-started/create-react-app)
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br>
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br>
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br>
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br>
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br>
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
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.
35+
36+
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.
37+
38+
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.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
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: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
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>
16-
)
9+
<div>
10+
<Suspense fallback={<div>Loading...</div>}>
11+
<Content />
12+
</Suspense>
13+
</div>
14+
);
1715
}
1816
}
1917

20-
export default App
18+
export default App;
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom'
3-
import App from './App'
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
44

55
it('renders without crashing', () => {
6-
const div = document.createElement('div')
7-
ReactDOM.render(<App />, div)
8-
ReactDOM.unmountComponentAtNode(div)
9-
})
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom'
3-
import App from './App'
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import './index.css';
4+
import App from './App';
5+
import * as serviceWorker from './serviceWorker';
46

5-
ReactDOM.render(<App />, document.getElementById('root'))
7+
ReactDOM.render(<App />, document.getElementById('root'));
8+
9+
// If you want your app to work offline and load faster, you can change
10+
// unregister() to register() below. Note this comes with some pitfalls.
11+
// Learn more about service workers: http://bit.ly/CRA-PWA
12+
serviceWorker.unregister();
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)