Skip to content

Commit b830762

Browse files
committed
Initial commit for v2
1 parent b7d85d2 commit b830762

File tree

787 files changed

+74382
-234646
lines changed

Some content is hidden

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

787 files changed

+74382
-234646
lines changed

02/hello-react/.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

02/hello-react/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"semi": true,
4+
"useTabs": false,
5+
"tabWidth": 2
6+
}

02/hello-react/README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1-
2장
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
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/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `npm run build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

02/hello-react/package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,29 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"react": "^16.3.1",
7-
"react-dom": "^16.3.1",
8-
"react-scripts": "1.1.4"
6+
"react": "^16.8.6",
7+
"react-dom": "^16.8.6",
8+
"react-scripts": "3.0.0"
99
},
1010
"scripts": {
1111
"start": "react-scripts start",
1212
"build": "react-scripts build",
13-
"test": "react-scripts test --env=jsdom",
13+
"test": "react-scripts test",
1414
"eject": "react-scripts eject"
15+
},
16+
"eslintConfig": {
17+
"extends": "react-app"
18+
},
19+
"browserslist": {
20+
"production": [
21+
">0.2%",
22+
"not dead",
23+
"not op_mini all"
24+
],
25+
"development": [
26+
"last 1 chrome version",
27+
"last 1 firefox version",
28+
"last 1 safari version"
29+
]
1530
}
16-
}
31+
}

02/hello-react/public/index.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6-
<meta name="theme-color" content="#000000">
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
78
<!--
8-
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/
9+
manifest.json provides metadata used when your web app is installed on a
10+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1011
-->
11-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
12+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
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.
@@ -22,9 +22,7 @@
2222
<title>React App</title>
2323
</head>
2424
<body>
25-
<noscript>
26-
You need to enable JavaScript to run this app.
27-
</noscript>
25+
<noscript>You need to enable JavaScript to run this app.</noscript>
2826
<div id="root"></div>
2927
<!--
3028
This HTML file is a template.

02/hello-react/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"

02/hello-react/src/App.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
.my-div {
2-
background-color: aqua;
3-
font-size: 15px;
1+
.react {
2+
background: aqua;
3+
color: black;
4+
font-size: 48px;
5+
font-weight: bold;
6+
padding: 16px;
47
}

02/hello-react/src/App.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,20 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import './App.css';
33

4-
class App extends Component {
5-
render() {
6-
const text = '당신은 어썸한가요?';
7-
const condition = true;
8-
const style = {
9-
backgroundColor: 'gray',
10-
border: '1px solid black',
11-
height: Math.round(Math.random() * 300) + 50,
12-
width: Math.round(Math.random() * 300) + 50,
13-
WebkitTransition: 'all',
14-
MozTransition: 'all',
15-
msTransition: 'all'
16-
};
17-
18-
return (
19-
<div className="my-div">
20-
{/* 엘리먼트 밖에서는 이렇게 작성해요 */}
21-
<h1>리액트 안녕!</h1>
22-
<h2>{text}</h2>
23-
{ condition && '보여주세요' }
24-
<div
25-
style={style}
26-
// self-closed 태그에서만 작동하는 주석
27-
// 마지막 /> 가 꼭 새 줄에 있어야 합니다.
28-
/* 이렇게 작성할 수도 있고요 */
29-
/>
30-
// 여기 쓰는 건 그대로 렌더링됩니다.
31-
/* 여기에선 주석 못 써요 */
4+
function App() {
5+
const name = '리액트';
6+
return (
7+
<>
8+
{/* 주석은 이렇게 작성합니다. */}
9+
<div
10+
className="react" // 시작 태그를 여러 줄로 작성하게 된다면 여기에 주석을 작성 할 수 있습니다.
11+
>
12+
{name}
3213
</div>
33-
);
34-
}
14+
// 하지만 이런 주석이나 /* 이런 주석은 페이지에 그대로 나타나게 됩니다. */
15+
<input />
16+
</>
17+
);
3518
}
3619

3720
export default App;

02/hello-react/src/index.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
body {
22
margin: 0;
33
padding: 0;
4-
font-family: sans-serif;
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;
514
}

02/hello-react/src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App';
5-
import registerServiceWorker from './registerServiceWorker';
5+
import * as serviceWorker from './serviceWorker';
66

77
ReactDOM.render(<App />, document.getElementById('root'));
8-
registerServiceWorker();
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: https://bit.ly/CRA-PWA
12+
serviceWorker.unregister();

05/hello-react/src/registerServiceWorker.js renamed to 02/hello-react/src/serviceWorker.js

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// In production, we register a service worker to serve assets from local cache.
1+
// This optional code is used to register a service worker.
2+
// register() is not called by default.
23

34
// This lets the app load faster on subsequent visits in production, and gives
45
// it offline capabilities. However, it also means that developers (and users)
5-
// will only see deployed updates on the "N+1" visit to a page, since previously
6-
// cached resources are updated in the background.
6+
// will only see deployed updates on subsequent visits to a page, after all the
7+
// existing tabs open on the page have been closed, since previously cached
8+
// resources are updated in the background.
79

8-
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
9-
// This link also includes instructions on opting out of this behavior.
10+
// To learn more about the benefits of this model and instructions on how to
11+
// opt-in, read https://bit.ly/CRA-PWA
1012

1113
const isLocalhost = Boolean(
1214
window.location.hostname === 'localhost' ||
@@ -18,59 +20,74 @@ const isLocalhost = Boolean(
1820
)
1921
);
2022

21-
export default function register() {
23+
export function register(config) {
2224
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
2325
// The URL constructor is available in all browsers that support SW.
24-
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
26+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
2527
if (publicUrl.origin !== window.location.origin) {
2628
// Our service worker won't work if PUBLIC_URL is on a different origin
2729
// from what our page is served on. This might happen if a CDN is used to
28-
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
30+
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
2931
return;
3032
}
3133

3234
window.addEventListener('load', () => {
3335
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
3436

3537
if (isLocalhost) {
36-
// This is running on localhost. Lets check if a service worker still exists or not.
37-
checkValidServiceWorker(swUrl);
38+
// This is running on localhost. Let's check if a service worker still exists or not.
39+
checkValidServiceWorker(swUrl, config);
3840

3941
// Add some additional logging to localhost, pointing developers to the
4042
// service worker/PWA documentation.
4143
navigator.serviceWorker.ready.then(() => {
4244
console.log(
4345
'This web app is being served cache-first by a service ' +
44-
'worker. To learn more, visit https://goo.gl/SC7cgQ'
46+
'worker. To learn more, visit https://bit.ly/CRA-PWA'
4547
);
4648
});
4749
} else {
48-
// Is not local host. Just register service worker
49-
registerValidSW(swUrl);
50+
// Is not localhost. Just register service worker
51+
registerValidSW(swUrl, config);
5052
}
5153
});
5254
}
5355
}
5456

55-
function registerValidSW(swUrl) {
57+
function registerValidSW(swUrl, config) {
5658
navigator.serviceWorker
5759
.register(swUrl)
5860
.then(registration => {
5961
registration.onupdatefound = () => {
6062
const installingWorker = registration.installing;
63+
if (installingWorker == null) {
64+
return;
65+
}
6166
installingWorker.onstatechange = () => {
6267
if (installingWorker.state === 'installed') {
6368
if (navigator.serviceWorker.controller) {
64-
// At this point, the old content will have been purged and
65-
// the fresh content will have been added to the cache.
66-
// It's the perfect time to display a "New content is
67-
// available; please refresh." message in your web app.
68-
console.log('New content is available; please refresh.');
69+
// At this point, the updated precached content has been fetched,
70+
// but the previous service worker will still serve the older
71+
// content until all client tabs are closed.
72+
console.log(
73+
'New content is available and will be used when all ' +
74+
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75+
);
76+
77+
// Execute callback
78+
if (config && config.onUpdate) {
79+
config.onUpdate(registration);
80+
}
6981
} else {
7082
// At this point, everything has been precached.
7183
// It's the perfect time to display a
7284
// "Content is cached for offline use." message.
7385
console.log('Content is cached for offline use.');
86+
87+
// Execute callback
88+
if (config && config.onSuccess) {
89+
config.onSuccess(registration);
90+
}
7491
}
7592
}
7693
};
@@ -81,14 +98,15 @@ function registerValidSW(swUrl) {
8198
});
8299
}
83100

84-
function checkValidServiceWorker(swUrl) {
101+
function checkValidServiceWorker(swUrl, config) {
85102
// Check if the service worker can be found. If it can't reload the page.
86103
fetch(swUrl)
87104
.then(response => {
88105
// Ensure service worker exists, and that we really are getting a JS file.
106+
const contentType = response.headers.get('content-type');
89107
if (
90108
response.status === 404 ||
91-
response.headers.get('content-type').indexOf('javascript') === -1
109+
(contentType != null && contentType.indexOf('javascript') === -1)
92110
) {
93111
// No service worker found. Probably a different app. Reload the page.
94112
navigator.serviceWorker.ready.then(registration => {
@@ -98,7 +116,7 @@ function checkValidServiceWorker(swUrl) {
98116
});
99117
} else {
100118
// Service worker found. Proceed as normal.
101-
registerValidSW(swUrl);
119+
registerValidSW(swUrl, config);
102120
}
103121
})
104122
.catch(() => {

0 commit comments

Comments
 (0)