Skip to content

Commit 01294a9

Browse files
committed
feat: reactv17
1 parent 0ca9859 commit 01294a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+21232
-1348
lines changed

.babelrc

-11
This file was deleted.

.eslintrc

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
{
2-
"parser": "babel-eslint",
3-
"parserOptions": {
4-
"sourceType": "module",
5-
"ecmaFeatures": {
6-
"jsx": true
7-
}
8-
}
9-
// "rules": {
10-
// "indent": [
11-
// "error",
12-
// 4,
13-
// {"SwitchCase": 1}
14-
// ]
15-
// }
2+
"extends": [
3+
"react-app",
4+
"react-app/jest"
5+
]
166
}

.gitignore

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
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
810

11+
# production
12+
/build
13+
914
# misc
1015
.DS_Store
1116
.env.local
1217
.env.development.local
1318
.env.test.local
1419
.env.production.local
15-
/.idea
16-
/.vscode
17-
git.bash
1820

1921
npm-debug.log*
2022
yarn-debug.log*

LICENSE

-21
This file was deleted.

README.md

+58-31
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,70 @@
1-
# React-SPA
2-
[![node-image](https://img.shields.io/badge/node.js-%3E=_4.0-green.svg?style=flat-square)](https://img.shields.io/badge/node.js-%3E=_4.0-green.svg?style=flat-square)
3-
[![npm-image](https://img.shields.io/npm/v/npm.svg?style=flat-square)](https://img.shields.io/npm/v/npm.svg?style=flat-square)
4-
[![download-image](https://img.shields.io/npm/dm/npm.svg?style=flat-square)](https://img.shields.io/npm/dm/npm.svg?style=flat-square)
1+
# Getting Started with Create React App
52

3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
64

7-
## Features
5+
## Available Scripts
86

9-
- TypeScript🚀
10-
- CSS Modules 🚀
11-
- Redux + React Router v4
12-
- Webpack 3.x
13-
- Mock
14-
- Eslint
7+
In the project directory, you can run:
158

16-
## Getting Started
17-
Checkout this repo, install dependencies, then start the process with the following:
9+
### `yarn start`
1810

19-
```bash
20-
> git clone https://github.com/allan2coder/React-SPA.git
21-
> cd React-SPA
22-
> npm install
23-
> npm start
24-
```
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
2513

26-
## Build the app
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
2716

28-
```bash
29-
npm run build
30-
```
17+
### `yarn test`
3118

32-
## Want more
33-
https://github.com/khno
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
3421

35-
## Reference
36-
* [Ant Design of React ](https://ant.design/docs/react/introduce-cn)
37-
* [Create-react-app ](https://github.com/facebookincubator/create-react-app)
38-
* [How to perform common tasks ](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#using-the-public-folder)
22+
### `yarn build`
3923

24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
4026

41-
## License
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
4229

43-
MIT
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `yarn 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/).
47+
48+
### Code Splitting
49+
50+
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)
51+
52+
### Analyzing the Bundle Size
53+
54+
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)
55+
56+
### Making a Progressive Web App
57+
58+
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)
59+
60+
### Advanced Configuration
61+
62+
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)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `yarn build` fails to minify
69+
70+
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)

config/env.js

+31-18
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,39 @@ if (!NODE_ENV) {
1515
}
1616

1717
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18-
var dotenvFiles = [
18+
const dotenvFiles = [
1919
`${paths.dotenv}.${NODE_ENV}.local`,
20-
`${paths.dotenv}.${NODE_ENV}`,
2120
// Don't include `.env.local` for `test` environment
2221
// since normally you expect tests to produce the same
2322
// results for everyone
2423
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
24+
`${paths.dotenv}.${NODE_ENV}`,
2525
paths.dotenv,
2626
].filter(Boolean);
2727

2828
// Load environment variables from .env* files. Suppress warnings using silent
2929
// if this file is missing. dotenv will never modify any environment variables
30-
// that have already been set.
30+
// that have already been set. Variable expansion is supported in .env files.
3131
// https://github.com/motdotla/dotenv
32+
// https://github.com/motdotla/dotenv-expand
3233
dotenvFiles.forEach(dotenvFile => {
3334
if (fs.existsSync(dotenvFile)) {
34-
require('dotenv').config({
35-
path: dotenvFile,
36-
});
35+
require('dotenv-expand')(
36+
require('dotenv').config({
37+
path: dotenvFile,
38+
})
39+
);
3740
}
3841
});
3942

4043
// We support resolving modules according to `NODE_PATH`.
4144
// This lets you use absolute paths in imports inside large monorepos:
42-
// https://github.com/facebookincubator/create-react-app/issues/253.
45+
// https://github.com/facebook/create-react-app/issues/253.
4346
// It works similar to `NODE_PATH` in Node itself:
4447
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
4548
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
46-
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
47-
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
49+
// Otherwise, we risk importing Node.js core modules into an app instead of webpack shims.
50+
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
4851
// We also resolve them to make sure all tools using them work consistently.
4952
const appDirectory = fs.realpathSync(process.cwd());
5053
process.env.NODE_PATH = (process.env.NODE_PATH || '')
@@ -54,7 +57,7 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '')
5457
.join(path.delimiter);
5558

5659
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
57-
// injected into the application via DefinePlugin in Webpack configuration.
60+
// injected into the application via DefinePlugin in webpack configuration.
5861
const REACT_APP = /^REACT_APP_/i;
5962

6063
function getClientEnvironment(publicUrl) {
@@ -74,17 +77,27 @@ function getClientEnvironment(publicUrl) {
7477
// This should only be used as an escape hatch. Normally you would put
7578
// images into the `src` and `import` them in code to get their paths.
7679
PUBLIC_URL: publicUrl,
80+
// We support configuring the sockjs pathname during development.
81+
// These settings let a developer run multiple simultaneous projects.
82+
// They are used as the connection `hostname`, `pathname` and `port`
83+
// in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
84+
// and `sockPort` options in webpack-dev-server.
85+
WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST,
86+
WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
87+
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
88+
// Whether or not react-refresh is enabled.
89+
// react-refresh is not 100% stable at this time,
90+
// which is why it's disabled by default.
91+
// It is defined here so it is available in the webpackHotDevClient.
92+
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
7793
}
7894
);
79-
// Stringify all values so we can feed into Webpack DefinePlugin
95+
// Stringify all values so we can feed into webpack DefinePlugin
8096
const stringified = {
81-
'process.env': Object.keys(raw).reduce(
82-
(env, key) => {
83-
env[key] = JSON.stringify(raw[key]);
84-
return env;
85-
},
86-
{}
87-
),
97+
'process.env': Object.keys(raw).reduce((env, key) => {
98+
env[key] = JSON.stringify(raw[key]);
99+
return env;
100+
}, {}),
88101
};
89102

90103
return { raw, stringified };

config/getHttpsConfig.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const crypto = require('crypto');
6+
const chalk = require('react-dev-utils/chalk');
7+
const paths = require('./paths');
8+
9+
// Ensure the certificate and key provided are valid and if not
10+
// throw an easy to debug error
11+
function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
12+
let encrypted;
13+
try {
14+
// publicEncrypt will throw an error with an invalid cert
15+
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
16+
} catch (err) {
17+
throw new Error(
18+
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
19+
);
20+
}
21+
22+
try {
23+
// privateDecrypt will throw an error with an invalid key
24+
crypto.privateDecrypt(key, encrypted);
25+
} catch (err) {
26+
throw new Error(
27+
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
28+
err.message
29+
}`
30+
);
31+
}
32+
}
33+
34+
// Read file and throw an error if it doesn't exist
35+
function readEnvFile(file, type) {
36+
if (!fs.existsSync(file)) {
37+
throw new Error(
38+
`You specified ${chalk.cyan(
39+
type
40+
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
41+
);
42+
}
43+
return fs.readFileSync(file);
44+
}
45+
46+
// Get the https config
47+
// Return cert files if provided in env, otherwise just true or false
48+
function getHttpsConfig() {
49+
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
50+
const isHttps = HTTPS === 'true';
51+
52+
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
53+
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
54+
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
55+
const config = {
56+
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
57+
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
58+
};
59+
60+
validateKeyAndCerts({ ...config, keyFile, crtFile });
61+
return config;
62+
}
63+
return isHttps;
64+
}
65+
66+
module.exports = getHttpsConfig;

config/jest/babelTransform.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const babelJest = require('babel-jest');
4+
5+
const hasJsxRuntime = (() => {
6+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
7+
return false;
8+
}
9+
10+
try {
11+
require.resolve('react/jsx-runtime');
12+
return true;
13+
} catch (e) {
14+
return false;
15+
}
16+
})();
17+
18+
module.exports = babelJest.createTransformer({
19+
presets: [
20+
[
21+
require.resolve('babel-preset-react-app'),
22+
{
23+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
24+
},
25+
],
26+
],
27+
babelrc: false,
28+
configFile: false,
29+
});

config/jest/cssTransform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
// This is a custom Jest transformer turning style imports into empty objects.
4-
// http://facebook.github.io/jest/docs/tutorial-webpack.html
4+
// http://facebook.github.io/jest/docs/en/webpack.html
55

66
module.exports = {
77
process() {

0 commit comments

Comments
 (0)