Ryu
  • 👩🏻‍💻 Ryu / software_engineer
  • ✨Resume
  • Python3
    • Python3 가상환경 설정하기
      • Python3 vs Python2
      • Pyenv
      • Venv
      • Pip
    • Flask
      • Flask 설치하기
      • API Server 만들기
    • REST API
    • Command Line 활용하기
    • Module 사용하기
      • Pickle - 자료형을 파일로 저장할 때
    • MongoDB connection
      • Pymongo
    • WSGI
      • 💡WSGI 가 필요한 이유
      • Web Server / WSGI / Middleware / Application 구조
      • WSGI Middleware 종류
      • Gunicorn
        • Gunicorn vs Uwsgi
    • Dockerize
      • 💡Dockerize 가 필요한 이유
      • 1. Create Dockerfile
        • Gunicorn 으로 nginx 와 app 연결하기
    • Kubernetes 로 배포하기
      • 💡Kubernetes 가 필요한 이유
      • Helm 사용하기
      • Helm 으로 k8s 에 앱 배포하기
  • Open Tracing (정리중)
    • Open Tracing 이란 무엇인가
    • Python OpenTracing Example
    • Jaeger, Jaeger UI
    • Python Jaeger Tutorial
    • Zipkin 알아보기
    • Jaeger-client 리스팅
  • Microservice Architecture
    • Netflix의 MSA 컨셉
      • ⚡️ MSA 를 도입할때 고려해야할 점들
  • Paper
    • Dynamo: Amazon’s Highly Available Key-value Store
      • 1. Introduction
      • 2. Background
      • 3. Related Work
        • Related Paper) Pastry, Chord
        • Byzantine Fault Tolerance
      • 4. System Architecture
        • 4.1 System Interface
        • 4.2 Partitioning
        • 4.3 Replication
        • Hash Function
  • Frontend
    • CommonJS 와 AMD
    • RequireJS
    • WebSocket
      • WebSocket vs Socket.io
      • polling vs long polling vs streaming
    • Vue.js
      • Vue.js 에서 WebSocket 사용하기
      • [프로젝트] Vue, Vuex, AntDesignVue 로 운영툴 만들기
    • React x Redux 로 프로젝트 만들기
      • 0. React, Redux 를 선택한 이유
      • 1. 프로젝트 생성하고 Webpack4 적용하기
      • 2. React 와 ReactDOM 적용하기
      • 3. Material UI 적용하기
  • Data Engineering
    • Spark
      • Spark 이란?
      • 각 데몬의 역할 Driver, Master, Worker
      • 장단점 / 함께사용하는 툴 / 사용 사례
  • Service Mesh (정리중)
    • RPC
    • gRPC - Python Server 만들기
      • step 2.
Powered by GitBook
On this page
  • 2. React 와 ReactDOM 적용하기
  • 짝짝짝! 👏🏻👏🏻

Was this helpful?

  1. Frontend
  2. React x Redux 로 프로젝트 만들기

2. React 와 ReactDOM 적용하기

Previous1. 프로젝트 생성하고 Webpack4 적용하기Next3. Material UI 적용하기

Last updated 6 years ago

Was this helpful?

2. React 와 ReactDOM 적용하기

React의 DOM 렌더링 과정은 참고하여 공부했습니다. 이와 관련해서 이후 포스팅을 할 예정입니다.

React, ReactDOM 설치하기

$ npm install --save react react-dom

/index.js 에서 사용해보기

import React from "react";
import ReactDOM from "react-dom";

let Hi = () => {
    return <h1>Hi Ryu!</h1>
};

ReactDOM.render(
    <Hi/>,
    document.getElementById("root")
);

이제 React 코드를 어떻게 컴파일해야할지 Webpack 에게 알려주는 역할이 필요합니다.

Babel 이 바로 그 역할을 합니다.

Babel packages 설치하기

$ npm install --save-dev @babel/core @babel/node @babel/preset-env @babel/preset-react babel-loader

더불어, 앞으로 css 파일들을 사용하여 스타일을 줄수 있도록 style 관련 loader 와 File 관련 loader 를 추가로 설치해주었습니다.

$ npm install --save-dev style-loader css-loader sass-loader node-sass$ npm install --save-dev file-loader @babel/plugin-proposal-class-properties

이제 Babel 의 설정파일을 추가하여 Webpack이 React와 스타일 관련 코드들을 컴파일할 수 있도록 해야합니다.

Babel Config 작성하기

$ vi .babelrc

/.babelrc 에 아래와 같이 작성합니다.

{
  "presets": [
    "@babel/env",
    "@babel/react"
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties"
  ]
}

Webpack.config.js 의 module.rules 에 loader 정보 추가해주기

config.module = {
    rules: [
        {
            // this is so that we can compile any React,
            // ES6 and above into normal ES5 syntax
            test: /\.(js|jsx)$/,
            // we do not want anything from node_modules to be compiled
            exclude: /node_modules/,
            use: ['babel-loader']
        },
        {
            test: /\.(css|scss)$/,
            use: [
                "style-loader", // creates style nodes from JS strings
                "css-loader", // translates CSS into CommonJS
                "sass-loader" // compiles Sass to CSS, using Node Sass by default
            ]
        },
        {
            test: /\.(jpg|jpeg|png|gif|mp3|svg)$/,
            loaders: ['file-loader']
        }
    ]
};

package.json scripts 수정하기

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "build-dev": "babel-node ./node_modules/webpack/bin/webpack --mode development",
  "build": "babel-node ./node_modules/webpack/bin/webpack --mode production",
  "dev": "babel-node ./node_modules/webpack-dev-server/bin/webpack-dev-server --open --mode development"
},

이제 모든 설정이 끝났습니다!

CSS 파일을 하나 만들어서 스타일이 잘 적용되는지 확인해봅시다!

  • src 폴더 하위에 style.css 파일을 하나 생성하고 body #root {font-size: 50px} 와 같이 간단한 스타일을 선언해줍니다.

  • 그 다음, index.js 에서 이를 import 한뒤 (import "./style.css" ) - 서버를 띄웁니다.

$ npm run dev

그럼 아래와 같이 스타일이 적용된 것을 확인할 수 있습니다.

짝짝짝! 👏🏻👏🏻

이제 기본적인 셋팅은 끝이 났습니다.

다음으로는 Redux 를 사용해보겠습니다.

이 문서를