์์ฝ:
npx create-react-app ํด๋๋ช
npm start
์ฑ๊ธํ์ด์ง์ ํ๋ฆฌ์ผ์ด์ ์ธ ๋ฆฌ์กํธ๋ ๋งค ํ์ด์ง๋ฅผ ์ ํํ๋ ๊ฒ์ด ์๋๋ผ
์๋ฐ์คํฌ๋ฆฝํธ๋ก ํ๋์ HTML ํ์ด์ง ์์์ ๊ณ์ ์๋ก์ด ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋๊ฐ๋ ํ์(์์ ์๋ ๋ด์ฉ๋ง ๊ณ์ ๋ฐ๊ฟ์ค)์ผ๋ก,
ํ์ด์ง๊ฐ ์ฌ๋ฌ๊ฐ์ธ ๊ฒ์ฒ๋ผ ๋ณด์ด๊ฒ๋ ํ๋ค.
์ฆ, ์น์ ์ฑ์ฒ๋ผ ๋ณด์ฌ์ฃผ๊ฒ ๋ง๋๋ ๋์์์ ๊ฐ๋ฅ์ผ ํ๋ค.
1: Nodejs ์ค์นํ๊ธฐ
node -v ๋ช ๋ น์ด๋ฅผ ํตํด nodejs๊ฐ ์ค์น ํ์ธ
- npm : Node Package Manager. NodeJS๋ก ๊ฐ๋ฐ๋ ๋ชจ๋๋ค์ ์ค์นํ๊ณ ๊ด๋ฆฌํด์ฃผ๋ ํจํค์ง ๋งค๋์ ธ
- nodeJS๋ก ๋ง๋ค์ด์ง ์ ์ฉํ ๋ชจ๋๋ค์ ๊ฐ์ ธ๋ค ์ฐ๊ณ ๊ด๋ฆฌ
2: ํ๋ก์ ํธ ์์ :
๋ฆฌ์กํธ์ ํ์ํ ํจํค์ง๋ฅผ ์๋์ผ๋ก ์ค์นํด์ฃผ๋ ๋ช ๋ น์ด ์ ๋ ฅ
- ํ๋ก์ ํธ๋ฅผ ์ค์นํ๊ณ ์ถ์ ๊ฒฝ๋ก์์
- npx create-react-app ํด๋๋ช
์ํตํด ์ค์น์๋ฅผ ๋ค๋ฉด,
npx create-react-app todoApp - Happy hacking ๋ฉ์ธ์ง๊ฐ ๋์ค๋ฉด ์ฑ๊ณต
npx create-react-app first-react
Need to install the following packages:
create-react-app
Ok to proceed? (y) y
Creating a new React app in C:\Users\User\Project\first-react.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
added 1377 packages in 2m
179 packages are looking for funding
run `npm fund` for details
Initialized a git repository.
Installing template dependencies using npm...
npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
added 39 packages in 11s
179 packages are looking for funding
run `npm fund` for details
Removing template package using npm...
removed 1 package, and audited 1416 packages in 5s
179 packages are looking for funding
run `npm fund` for details
6 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
Created git commit.
Success! Created first-react at C:\Users\User\progect\first-react
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd first-react
npm start
Happy hacking!
public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
<div id="root"></div>
3: SPA : ๋ฆฌ์กํธ ์์๋ HTML ํ์ด์ง๋ ๋จ ํ๋, ํ๊ทธ๋ ๋จ ํ๋์ด๋ค.
Single Page Application์ ์ค๋ง ์ฆ ํ์ด์ง๊ฐ ํ๋๋ผ๋ ๋ป
ํ๋์ ํ์ด์ง ์์์ ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ํ์ํ ํ์ด์ง๋ ์ ๋ณด๋ง ๋์ ์ผ๋ก ๊ทธ๋ ค์ค๋ค. ์ฆ, ์ ํ์ด์ง๋ก ๋์ด๊ฐ๋๋ง๋ค ์๋ฒ์์ HTML CSS JS ์์ค๋ฅผ ๊ฐ์ ธ์ฌ ํ์๊ฐ ์์ด ์๋ก๊ณ ์นจ์ด ํ์์๋ค. ๋ฐ๋ผ์ ์ฌ์ฉ์์๊ฒ ๋ฌผํ๋ฅด๋ฏ ๋๊น์๋ ์น์ฑ ๊ฒฝํ
๋จ์ ์ ์ฒ์์ ํ์ํ ๋ฆฌ์์ค๋ฅผ ๋ค ๊ฐ์ ธ์์ผ ํด์ ์ด๊ธฐ ๊ตฌ๋ ์๋๊ฐ ๋๋ฆฌ๋ค.
src/index.js : HTML๊ณผ JS๋ฅผ ์ฐ๊ฒฐํด์ฃผ๋ ์ฐ๊ฒฐ๊ณ ๋ฆฌ๋ธ๋ฆฟ์ง ์ฆ, html ํ์ผ์ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์น์ด์ฃผ๋ ์์ ์ ์ํํจ
index.js ์ญํ ์ index.html๊ณผ App.js๋ฅผ ์ฐ๊ฒฐ
์ฌ๋งํด์๋ ๊ฑด๋๋ฆด ์ผ์ด ์๋ ํ์ผ
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
ReactDOM.render์ ์ ํํ html ํ๊ทธ์ react๋ฅผ ๊ทธ๋ ค์ค๋ค(์ ํํ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์น๋๋ค)
์ฆ, ์ฝ๋๋
root๊ฐ id์ธ ํ๊ทธ๋ฃฐ ๋ค๊ณ ์์, ๊ฑฐ๊ธฐ๋ค App์ด๋ผ๋ react ์ปดํฌ๋ํธ๋ฅผ ์น์ด์ค๋ค๊ณ ํด์ํ ์ ์๋ค.
์์ผ๋ก ๋ฆฌ์กํธ ์์ ์ ๋ชจ๋ App.js์ ๋ค์ด๊ฐ๊ฒ ๋ ๊ฒ์ด๋ค.
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
์ ํํ html ํ๊ทธ์ react๋ฅผ ๊ทธ๋ ค์ค
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
reportWebVitals();
src/App.js : ํ๋ก์ ํธ(๋ฆฌ์กํธ ๊ธฐ๋ณธ ์ธํ ๊ฐ)
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
4: npm start
์ ํ๋ฉด์ด ๋ณด์ด๋ฉด ์ฑ๊ณต~~~
App.js ๋ฅผ ์ด๋ ๊ฒ ๋ฐ๊พธ๋ฉด...
import "./App.css";
function App() {
return (
<div className="App">
<header className="App-header">์๋
ํ์ธ์ ๋ฆฌ์กํธ ์
๋๋ค.</header>
</div>
);
}
export default App;
C:\Users\User\gitprogect\bokkieProject\first-react\src\App.css ์ ๋ด์ฉ์ ์์ผ๋ก ์ธ ์ผ์ด ์๋ค๋ฉด ์ง์์ฃผ๋ฉด ๋๋ค.
'Javascript > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] fontawesome ๋ฆฌ์กํธ๋ก ๊ฐ์ ธ์ค๊ธฐ (0) | 2022.12.26 |
---|---|
[React] ๋ฆฌ์กํธ ๋ผ์ฐํฐ์ ๊ด๋ จ Hooks ์ ๋ฆฌ (0) | 2022.12.14 |
[๋ฆฌ์กํธ] ์ปดํฌ๋ํธ ๋จ์ถํค ๊นกํจ rafce (0) | 2022.05.23 |
[React] index.html ์ ๋ฆฌ์กํธ์ ๋ฐ๋ฒจ ๋ถ๋ฌ์ค๊ธฐ (0) | 2022.04.23 |