Jieunny์˜ ๋ธ”๋กœ๊ทธ

S4) Unit 3. [์‹ค์Šต] ๋ฆฌ์•กํŠธ ์›น์•ฑ ๋ฒˆ๋“ค๋ง ํ›„ ๋ฐฐํฌํ•˜๊ธฐ ๋ณธ๋ฌธ

CodeStates/Training

S4) Unit 3. [์‹ค์Šต] ๋ฆฌ์•กํŠธ ์›น์•ฑ ๋ฒˆ๋“ค๋ง ํ›„ ๋ฐฐํฌํ•˜๊ธฐ

Jieunny 2023. 3. 21. 13:07

๐Ÿ“ฃ  ๋‚˜๋งŒ์˜ ์•„๊ณ ๋ผ์Šคํ…Œ์ด์ธ (๋ฆฌ์•กํŠธ ๋ฆฌํŒฉํ† ๋ง) ์›น์•ฑ ๋ฒˆ๋“ค๋ง ํ›„ ๋ฐฐํฌํ•˜๊ธฐ

๐Ÿ“š ์ฐธ๊ณ  : https://velog.io/@seul_/%EB%A6%AC%EC%95%A1%ED%8A%B8-%EC%9B%B9%EC%95%B1-%EB%B2%88%EB%93%A4%EB%A7%81-%ED%9B%84-%EB%B0%B0%ED%8F%AC%EC%9B%B9%ED%8C%A9%EC%9C%BC%EB%A1%9C-CRA%EC%97%86%EC%9D%B4-%EB%A6%AC%EC%95%A1%ED%8A%B8-%EA%B0%9C%EB%B0%9C%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%B6%95

 

๐Ÿšจ ๋ƒ…๋‹ค ๋”ฐ๋ผํ•˜๋‹ค๊ฐ€ ๋ญ ์ž˜๋ชป๋งŒ์กŒ๋Š”์ง€ ๋ฆฌ์•ก๋“œ ์•ฑ ์ž์ฒด๊ฐ€ ์•ˆ์ผœ์ ธ์„œ ์ƒˆ ํ”Œ์  ๋งŒ๋“ค์—ˆ๋‹ค..

์„œ๋ฒ„๋ž‘ ์—ฐ๊ฒฐ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”๊ฑด๋ฐ..

 

๐Ÿญ. ๊ฐœ๋ฐœํ™˜๊ฒฝ ์ดˆ๊ธฐํ™”

npm i -y

 

๐Ÿฎ. ๋ฆฌ์•กํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

npm i react react-dom

 

๐Ÿฏ. ์›นํŒฉ ์„ค์น˜

npm i -D webpack webpack-cli

 

๐Ÿฐ. package.json ์ˆ˜์ •

 "build": "webpack",

โžฐ build๋ฅผ webpack์œผ๋กœ ์ˆ˜์ •ํ•ด์ค€๋‹ค.

 

๐Ÿฑ. ๋ฐ”๋ฒจ ์„ค์น˜

npm i -D babel-loader @babel/core @babel/preset-env @babel/preset-react

โžฐ JSX๋ฌธ๋ฒ•์œผ๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋Š” ๋ฐ”๋ฒจ์„ ํ†ตํ•ด์„œ JS์ฝ”๋“œ๋กœ ๋ณ€ํ™˜ํ•ด์„œ ๋ฒˆ๋“ค๋ง ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

 

๐Ÿฒ. CSS ๋ฒˆ๋“ค๋ง

npm i -D css-minimizer-webpack-plugin
npm i -D mini-css-extract-plugin
// CSS ํŒŒ์ผ์„ ํ•œ์ค„๋กœ ์••์ถ•

 

๐Ÿณ. HTML ๋ฒˆ๋“ค๋ง

npm install -D html-webpack-plugin

 

๐Ÿด. loader ์„ค์น˜

npm i file-loader -D

โžฐ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ฒˆ๋“ค๋ง ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์„ค์น˜ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

โžฐ ์ฒ˜์Œ์— ์•ˆํ•ด์คฌ๋”๋‹ˆ ์—๋Ÿฌ๋‚จ..

 

๐Ÿต. webpack.config.js ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ๊ตฌํ˜„

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');

module.exports = {
  entry: './src/index.js', // ๋นŒ๋“œ ์‹œ์ž‘ ์œ„์น˜
  output: {
    // ๋นŒ๋“œ๊ฒฐ๊ณผ ์ €์žฅ ์œ„์น˜
    filename: 'app.bundle.js',
    path: path.resolve(__dirname, 'docs'),
    clean: true,
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ['@babel/preset-env'],
              ['@babel/preset-react', { runtime: 'automatic' }],
            ],
          },
        },
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader'],
        exclude: /node_modules/,
      },
      {
        test: /\.jpeg$/,
        use: [
         {
           loader: 'file-loader',
           options: {
             name: '[name].[ext]'
             // ์ด๋ฆ„์ด ๋žœ๋คํ•œ ํ•ด์‹œ๊ฐ’์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ๊ฒƒ์„ ๋ง‰๊ธฐ ์œ„ํ•ด ์ด๋ฆ„์„ ๋”ฐ๋กœ ์„ค์ •ํ•ด์ค€๋‹ค.
            }
          },
        ],
 }  ,
    ],
  },
  optimization: {
    minimizer: [
      new CssMinimizerPlugin(), // css๋ฅผ ์ค„์—ฌ์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
    new MiniCssExtractPlugin({
      filename: 'style.css',
    }),
  ],
};

 

๐Ÿญ๐Ÿฌ. ๋นŒ๋“œํ•˜๊ธฐ

npm run build

โžฐ ๊นƒํ—ˆ๋ธŒ์— ๋ฐฐํฌํ• ๊ฑฐ๊ธฐ ๋•Œ๋ฌธ์— ์ฒ˜์Œ๋ถ€ํ„ฐ docs ํด๋”์— ๋นŒ๋“œ ํ•ด์คฌ๋‹ค.

 

๐Ÿ”— ๋ฐฐํฌ ๋งํฌ

https://jieuny0314.github.io/Agorastates-react/

 

React App

 

jieuny0314.github.io