Skip to content

Commit be003a9

Browse files
committed
chore(example): updated create-react-app example for v4 of react-scripts
1 parent 926053a commit be003a9

File tree

6 files changed

+64
-215
lines changed

6 files changed

+64
-215
lines changed

Diff for: examples/create-react-app/README.md

+33-58
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
# ReactMD and Create React App Example
22

3-
This project was bootstrapped with
4-
[Create React App](https://github.com/facebook/create-react-app) using
5-
[react-md](https://react-md.dev) as the component library.
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app) using [react-md](https://react-md.dev) as the component library.
64

75
## What's Included
86

9-
This example will setup an example Create React App + ReactMD app that has the
10-
following features:
7+
This example will setup an example Create React App + ReactMD app that has the following features:
118

12-
- [jsconfig.json](./jsconfig.json) to allow absolute imports instead of relative
13-
imports from the `"src"` directory
14-
- `import MyComponent from "components/MyComponent"` instead of
15-
`import MyComponent from "../../components/MyComponent"`
16-
- [\_variables.scss](./src/_variables.scss) to override the default `react-md`
17-
theme and feature toggles
9+
- [jsconfig.json](./jsconfig.json) to allow absolute imports instead of relative imports from the `"src"` directory
10+
- `import MyComponent from "components/MyComponent"` instead of `import MyComponent from "../../components/MyComponent"`
11+
- [\_variables.scss](./src/_variables.scss) to override the default `react-md` theme and feature toggles
1812
- a reusable [Layout.jsx](./src/components/Layout/Layout.jsx) that:
1913
- updates all the icons to use `SVGIcon`s instead of `FontIcon`s
2014
- initializes the `Layout` component from `react-md` with navigation items
21-
- uses [react-router-dom](https://www.npmjs.com/package/react-router-dom) as
22-
the routing library
15+
- uses [react-router-dom](https://www.npmjs.com/package/react-router-dom) as the routing library
2316

2417
## How to Use
2518

26-
Since this example is not a separate repo, this example will need to be manually
27-
downloaded instead of using `create-react-app`:
19+
Since this example is not a separate repo, this example will need to be manually downloaded instead of using `create-react-app`:
2820

2921
```bash
3022
curl https://codeload.github.com/mlaursen/react-md/tar.gz/main | tar -xz --strip=2 react-md-main/examples/create-react-app
@@ -51,96 +43,79 @@ git commit -m "Initial commit"
5143

5244
## Learn More
5345

54-
To learn more about react-md and Next.js, take a look at the following
55-
resources:
46+
To learn more about react-md and Next.js, take a look at the following resources:
5647

5748
- [react-md Documentation](https://react-md.dev)
5849
- [Configuring your Layout](https://react-md.dev/guides/configuring-your-layout)
5950
- [Create React App Documentation](https://create-react-app.dev/)
6051

52+
# Getting Started with Create React App
53+
54+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
55+
6156
## Available Scripts
6257

6358
In the project directory, you can run:
6459

6560
### `yarn start`
6661

67-
Runs the app in the development mode.<br /> Open
68-
[http://localhost:3000](http://localhost:3000) to view it in the browser.
62+
Runs the app in the development mode.\
63+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
6964

70-
The page will reload if you make edits.<br /> You will also see any lint errors
71-
in the console.
65+
The page will reload if you make edits.\
66+
You will also see any lint errors in the console.
7267

7368
### `yarn test`
7469

75-
Launches the test runner in the interactive watch mode.<br /> See the section
76-
about
77-
[running tests](https://facebook.github.io/create-react-app/docs/running-tests)
78-
for more information.
70+
Launches the test runner in the interactive watch mode.\
71+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
7972

8073
### `yarn build`
8174

82-
Builds the app for production to the `build` folder.<br /> It correctly bundles
83-
React in production mode and optimizes the build for the best performance.
75+
Builds the app for production to the `build` folder.\
76+
It correctly bundles React in production mode and optimizes the build for the best performance.
8477

85-
The build is minified and the filenames include the hashes.<br /> Your app is
86-
ready to be deployed!
78+
The build is minified and the filenames include the hashes.\
79+
Your app is ready to be deployed!
8780

88-
See the section about
89-
[deployment](https://facebook.github.io/create-react-app/docs/deployment) for
90-
more information.
81+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
9182

9283
### `yarn eject`
9384

9485
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
9586

96-
If you aren’t satisfied with the build tool and configuration choices, you can
97-
`eject` at any time. This command will remove the single build dependency from
98-
your project.
87+
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.
9988

100-
Instead, it will copy all the configuration files and the transitive
101-
dependencies (webpack, Babel, ESLint, etc) right into your project so you have
102-
full control over them. All of the commands except `eject` will still work, but
103-
they will point to the copied scripts so you can tweak them. At this point
104-
you’re on your own.
89+
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.
10590

106-
You don’t have to ever use `eject`. The curated feature set is suitable for
107-
small and middle deployments, and you shouldn’t feel obligated to use this
108-
feature. However we understand that this tool wouldn’t be useful if you couldn’t
109-
customize it when you are ready for it.
91+
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.
11092

11193
## Learn More
11294

113-
You can learn more in the
114-
[Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
95+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
11596

11697
To learn React, check out the [React documentation](https://reactjs.org/).
11798

11899
### Code Splitting
119100

120-
This section has moved here:
121-
https://facebook.github.io/create-react-app/docs/code-splitting
101+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
122102

123103
### Analyzing the Bundle Size
124104

125-
This section has moved here:
126-
https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
105+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
127106

128107
### Making a Progressive Web App
129108

130-
This section has moved here:
131-
https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
109+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
132110

133111
### Advanced Configuration
134112

135-
This section has moved here:
136-
https://facebook.github.io/create-react-app/docs/advanced-configuration
113+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
137114

138115
### Deployment
139116

140-
This section has moved here:
141-
https://facebook.github.io/create-react-app/docs/deployment
117+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
142118

143119
### `yarn build` fails to minify
144120

145-
This section has moved here:
146-
https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
121+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

Diff for: examples/create-react-app/package.json

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@
99
"eject": "react-scripts eject"
1010
},
1111
"dependencies": {
12-
"react": "^16.13.1",
13-
"react-dom": "^16.13.1",
12+
"@testing-library/jest-dom": "^5.11.6",
13+
"@testing-library/react": "^11.1.2",
14+
"@testing-library/user-event": "^12.2.2",
15+
"node-sass": "^4.14.1",
16+
"react": "^17.0.1",
17+
"react-dom": "^17.0.1",
1418
"react-md": "latest",
1519
"react-router-dom": "^5.2.0",
16-
"react-scripts": "3.4.1"
17-
},
18-
"devDependencies": {
19-
"@testing-library/jest-dom": "^4.2.4",
20-
"@testing-library/react": "^9.3.2",
21-
"@testing-library/user-event": "^7.1.2",
22-
"node-sass": "^4.14.1"
20+
"react-scripts": "4.0.0",
21+
"web-vitals": "^0.2.4"
2322
},
2423
"eslintConfig": {
25-
"extends": "react-app"
24+
"extends": [
25+
"react-app",
26+
"react-app/jest"
27+
]
2628
},
2729
"browserslist": {
2830
"production": [

Diff for: examples/create-react-app/src/index.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
33
import './index.scss';
44
import App from './App';
55
import { BrowserRouter as Router } from 'react-router-dom';
6-
import * as serviceWorker from './serviceWorker';
6+
import reportWebVitals from './reportWebVitals';
77

88
ReactDOM.render(
99
<Router>
@@ -12,7 +12,7 @@ ReactDOM.render(
1212
document.getElementById('root')
1313
);
1414

15-
// If you want your app to work offline and load faster, you can change
16-
// unregister() to register() below. Note this comes with some pitfalls.
17-
// Learn more about service workers: https://bit.ly/CRA-PWA
18-
serviceWorker.unregister();
15+
// If you want to start measuring performance in your app, pass a function
16+
// to log results (for example: reportWebVitals(console.log))
17+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18+
reportWebVitals();

Diff for: examples/create-react-app/src/reportWebVitals.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const reportWebVitals = (onPerfEntry) => {
2+
if (onPerfEntry && onPerfEntry instanceof Function) {
3+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4+
getCLS(onPerfEntry);
5+
getFID(onPerfEntry);
6+
getFCP(onPerfEntry);
7+
getLCP(onPerfEntry);
8+
getTTFB(onPerfEntry);
9+
});
10+
}
11+
};
12+
13+
export default reportWebVitals;

Diff for: examples/create-react-app/src/serviceWorker.js

-141
This file was deleted.

Diff for: examples/create-react-app/src/setupTests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// allows you to do things like:
33
// expect(element).toHaveTextContent(/react/i)
44
// learn more: https://github.com/testing-library/jest-dom
5-
import '@testing-library/jest-dom/extend-expect';
5+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)