-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
15 changed files
with
4,185 additions
and
2,559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,52 @@ | ||
import { Message } from 'rebass' | ||
|
||
# Create React App | ||
|
||
<Message> | ||
This docs page is a WIP | ||
</Message> | ||
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 | ||
[`create-react-app-rewired`][cra-rewired] and add a `config-overrides.js`. | ||
[`mdx.macro`][mdx-macro]. | ||
|
||
```sh | ||
npx create-react-app my-app | ||
yarn add mdx.macro | ||
``` | ||
|
||
Then create the following `src/App.js`: | ||
|
||
```js | ||
const { getBabelLoader } = require('react-app-rewired') | ||
|
||
module.exports = (config, env) => { | ||
const babelLoader = getBabelLoader(config.module.rules) | ||
config.module.rules.map(rule => { | ||
if (typeof rule.test !== 'undefined' || typeof rule.oneOf === 'undefined') { | ||
return rule | ||
} | ||
|
||
rule.oneOf.unshift({ | ||
test: /\.mdx$/, | ||
use: [ | ||
{ | ||
loader: babelLoader.loader, | ||
options: babelLoader.options | ||
}, | ||
'@mdx-js/loader' | ||
] | ||
}) | ||
|
||
return rule | ||
}) | ||
|
||
return config | ||
// src/App.js | ||
|
||
import React, { lazy, Component, Suspense } from 'react'; | ||
import { importMDX } from 'mdx.macro'; | ||
|
||
const Content = lazy(() => importMDX('./Content.mdx')); | ||
|
||
class App extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Suspense fallback={<div>Loading...</div>}> | ||
<Content /> | ||
</Suspense> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default App; | ||
``` | ||
|
||
And then create the following `src/Content.mdx`: | ||
|
||
```md | ||
# Hello, world! | ||
``` | ||
|
||
[See the full example][cra-example] | ||
|
||
[cra-rewired]: https://github.com/timarney/react-app-rewired | ||
[mdx-macro]: https://www.npmjs.com/package/mdx.macro | ||
|
||
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
{ | ||
"name": "create-react-app", | ||
"version": "0.1.0", | ||
"private": true, | ||
"name": "mdx-create-react-app", | ||
"dependencies": { | ||
"@mdx-js/loader": "^0.16.4", | ||
"@mdx-js/mdx": "^0.16.4", | ||
"mdx.macro": "^0.2.7", | ||
"react": "^16.6.3", | ||
"react-app-rewired": "^1.6.2", | ||
"react-dom": "^16.6.3", | ||
"react-scripts": "1.1.5" | ||
"react-scripts": "2.1.1" | ||
}, | ||
"scripts": { | ||
"start": "react-app-rewired start", | ||
"build": "react-app-rewired build", | ||
"test": "react-app-rewired test --env=jsdom" | ||
} | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
# MDX + Create React App | ||
# Create React App | ||
|
||
```shell | ||
npm install | ||
npm start | ||
``` | ||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
|
||
[See documentation](https://mdxjs.com/getting-started/create-react-app) | ||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `npm start` | ||
|
||
Runs the app in the development mode.<br> | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
||
The page will reload if you make edits.<br> | ||
You will also see any lint errors in the console. | ||
|
||
### `npm test` | ||
|
||
Launches the test runner in the interactive watch mode.<br> | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
||
### `npm run build` | ||
|
||
Builds the app for production to the `build` folder.<br> | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.<br> | ||
Your app is ready to be deployed! | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
||
### `npm run eject` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
||
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. | ||
|
||
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. | ||
|
||
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. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
animation: App-logo-spin infinite 20s linear; | ||
height: 40vmin; | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const Demo = () => ( | ||
<div style={{ padding: 20, backgroundColor: "tomato" }} /> | ||
); | ||
|
||
# Hello, world! | ||
|
||
<Demo /> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", | ||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", | ||
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", | ||
monospace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import './index.css' | ||
import App from './App' | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
9cb7c3a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://mdx-iperqmrboe.now.sh to the following aliases.