whatisthis?

220315 [TIL] Today I Learned ๐Ÿ’ฏ React.js - (2) ๋ณธ๋ฌธ

WEB STUDY/REACT

220315 [TIL] Today I Learned ๐Ÿ’ฏ React.js - (2)

thisisyjin 2022. 3. 15. 18:02

React.js   

Day 03 React Hooks + WebPack 

 

 

๐Ÿ’พ PART 1

 

220315 [TIL] Today I Learned ๐Ÿ’ฏ React.js - (1)

React.js Day 03 React Hooks + WebPack 1 / React Hooks ๋ฆฌ์•กํŠธ์—์„œ ์ถ”์ฒœํ•˜๋Š” ๊ฒƒ = Hooks์˜ ์‚ฌ์šฉ. Class Component๋ฅผ ์ž์ œํ•˜๊ณ , ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์œ„ํ•œ Hooks๋ฅผ ๊ถŒ๊ณ ํ•จ. ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ class Button extends..

mywebproject.tistory.com

 

 

* ์ง€๊ธˆ๊นŒ์ง€์˜ ์ฝ”๋“œ

 

๐Ÿ“ƒ webpack.config.js

const path = require("path");

module.exports = {
  name: "wordrelay-setting",
  mode: "development", // ์‹ค์„œ๋น„์Šค์—์„  'production'์œผ๋กœ
  devtool: "eval", // ๋น ๋ฅด๊ฒŒ
  resolve: {
    extensions: [".js", ".jsx"],
  },
  
  entry: {
    app: ["./client.jsx", "WordRealy.jsx"],
  },
  output: {
    path: path.join(__dirname, "dist"), //__dirname์€ ํ˜„์žฌํด๋”๊ฒฝ๋กœ
    filename: "app.js",
  },
};

 

์ฐธ๊ณ  - devtool์€ ๊ฐœ๋ฐœ์„ ์šฉ์ดํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์†Œ์Šค๋งต์„ ์ œ๊ณตํ•˜๋Š” ์˜ต์…˜.

๋‚œ๋…ํ™”๋œ ํŒŒ์ผ์€ ์˜ค๋ฅ˜๊ฐ€ ์–ด๋””์—์„œ ๋‚ฌ๋Š”์ง€ ํ™•์ธ์ด ํž˜๋“œ๋ฏ€๋กœ 

์†Œ์Šค๋งต์„ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

 

๐Ÿ“– ์•„๋ž˜ ๊ธ€์„ ์ฐธ๊ณ ํ•ด์„œ ํ›‘์–ด๋ณด์ž.

 

(Webpack) devtool ์˜ต์…˜ ํผํฌ๋จผ์Šค

๋ชฉ์ฐจ ๋“ค์–ด๊ฐ€๊ธฐ์— ์•ž์„œ ์†Œ์Šค๋งต devtool ๋งˆ์น˜๋ฉฐ… ๋“ค์–ด๊ฐ€๊ธฐ์— ์•ž์„œ์ด ํฌ์ŠคํŠธ์—์„œ๋Š” ์›นํŒฉ์— ๋Œ€ํ•œ ๊ธฐ์ดˆ ๋‚ด์šฉ์„ ์„ค๋ช…ํ•˜์ง€ ์•Š๋Š”๋‹ค.์›นํŒฉ์„ ๋ชจ๋ฅด๋Š” ์‚ฌ๋žŒ์€ ์‚ดํฌ์‹œ ๋’ค๋กœ๊ฐ€๊ธฐ๋ฅผ ๋ˆ„๋ฅด๋Š” ๊ฑธ ๊ถŒ์žฅํ•œ๋‹ค.

perfectacle.github.io


 

npx webpack

 

 

์ปค๋งจ๋“œ๋ผ์ธ์— ๋ช…๋ น์–ด๋ฅผ ์น˜๋ ค๋ฉด, ๋“ฑ๋ก์„ ํ•ด์ค˜์•ผํ•œ๋‹ค.

 

 

๋ฐฉ๋ฒ• 1 / ๋ช…๋ น์–ด๋กœ ๋“ฑ๋ก

๋ฐฉ๋ฒ• 2 / package.json์˜ "scripts" : {} ์•ˆ์— ์ ๊ธฐ

"scripts": {
    "dev": "webpack"
  },

 

๋ฐฉ๋ฒ• 3 / $npx webpack ์ด๋ผ๊ณ  ์ž…๋ ฅ

- ๐Ÿ™‹‍โ™‚๏ธ ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๋ณด์ž!

 

Module parse failed: Unexpected token (6:16)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const WordRelay = require("./WordRelay");
|
> ReactDom.render(<WordRelay />, document.querySelector("#root"));
|

 

๊ทธ๋Ÿฌ๋ฉด ์ด๋Ÿฐ์‹์œผ๋กœ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

๋Œ€์ถฉ ํ•ด์„ํ•˜์ž๋ฉด,

" Module์„ ์ฐพ๋Š”๊ฑธ ์‹คํŒจํ–ˆ๋‹ค

-> ์ด file ํƒ€์ž…์„ ๋‹ค๋ฃจ๋ ค๋ฉด, ์ ์ ˆํ•œ loder๊ฐ€ ํŒ”์š”ํ•˜๋‹ค. "

 

>>  jsx๋ฅผ ํ•ด์„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ”๋ฒจ ์…‹ํŒ…์„ ํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ์—๋Ÿฌ๊ฐ€ ๋‚œ๊ฒƒ์ž„.

 

๋ฐ”๋ฒจ์„ ์„ค์น˜ํ•œ๋‹ค๊ณ  ๋ฐ”๋กœ JSX๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋‚˜? >> โŒ
๋ฐ”๋ฒจ ๋‚ด์—์„œ๋„ ์„ค์ •์„ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.


1 / ํ•„์š”ํ•œ ๋ฐ”๋ฒจ ์„ค์น˜ํ•˜๊ธฐ
$ npm i -D @babel/core @babel/preset-env @babel/preset-react babel-loader


- core : ๊ธฐ๋ณธ์ ์ธ ๊ฒƒ ํฌํ•จ
- preset-env : ๋ธŒ๋ผ์šฐ์ €์— ๋งž๊ฒŒ ์ตœ์‹ ๋ฌธ๋ฒ•์„ ์˜›๋‚ ๋ฌธ๋ฒ•์œผ๋กœ ๋ฐ”๊ฟ”์คŒ
- preset-react : JSX๋ฅผ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ
- babel-loader : ๋ฐ”๋ฒจ๊ณผ ์›นํŒฉ ์—ฐ๊ฒฐ


package.json ํ™•์ธ 

"devDependencies": {
    "@babel/core": "^7.17.7",
    "@babel/plugin-proposal-class-properties": "^7.16.7",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "babel-loader": "^8.2.3",
    // ์ƒ๋žต
}



2 / webpack.config.js ์ˆ˜์ •

module ๋ผ๋Š” ํ”„๋กœํผํ‹ฐ ์ถ”๊ฐ€ ํ›„,
rules ๋ผ๋Š” ๋ฐฐ์—ด์•ˆ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ์–ด์คŒ.

module: {
    rules: [
      {
        test: /\.jsx?/, // ์ •๊ทœํ‘œํ˜„์‹ -js๋‚˜ jsx
        loader: "babal-loader",
        options: {
          presets: ["@babel/preset-env", "@babel/preset-react"],
        },
      },
    ],
  },


test - ํŒŒ์ผ์ด js๋‚˜ jsx์ธ์ง€ ํ…Œ์ŠคํŠธํ•˜๋ผ๋Š” ์˜๋ฏธ.
์ •๊ทœํ‘œํ˜„์‹์œผ๋กœ ์ž‘์„ฑํ–ˆ๋Š”๋ฐ, ์•„๋ž˜ ๋ฌธ์„œ ์ฐธ๊ณ .

loader - babel-loader์„ ์“ฐ๋ผ๋Š” ์˜๋ฏธ.


(cr: babelsjs.io)
๐Ÿ™‹‍โ™‚๏ธ Using a Preset

Within a Babel config, if the preset is on npm, you can pass in the name of the preset and
Babel will check that it's installed in node_modules already.
This is added to the presets config option, which takes an array.


3 / ๋‹ค์‹œํ•œ๋ฒˆ $ npx webpack ์ž…๋ ฅํ•˜๊ธฐ


๋“œ๋””์–ด ์ •์ƒ์ ์œผ๋กœ built ์™„๋ฃŒ ๐Ÿ˜‚

 

๐Ÿš€ ์ •๊ทœํ‘œํ˜„์‹ ์ด๋ž€?

 

์ •๊ทœ ํ‘œํ˜„์‹ - JavaScript | MDN

์ •๊ทœ ํ‘œํ˜„์‹, ๋˜๋Š” ์ •๊ทœ์‹์€ ๋ฌธ์ž์—ด์—์„œ ํŠน์ • ๋ฌธ์ž ์กฐํ•ฉ์„ ์ฐพ๊ธฐ ์œ„ํ•œ ํŒจํ„ด์ž…๋‹ˆ๋‹ค. JavaScript์—์„œ๋Š” ์ •๊ทœ ํ‘œํ˜„์‹๋„ ๊ฐ์ฒด๋กœ์„œ, RegExp์˜ exec()์™€ test() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. String์˜ match(), matchA

developer.mozilla.org

/   /  ์•ˆ์— ์ž‘์„ฑ.

\.๋Š” ์ด์Šค์ผ€์ดํ•‘ = "."์„ ์˜๋ฏธํ•จ.

 

 

๐Ÿ”ป ์˜ˆ์ œ 

๋”๋ณด๊ธฐ

 

์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ํ›„ "ํ™•์ธ" ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด์„ธ์š”.
###-####-####์˜ ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•˜์„ธ์š”.

const form = document.querySelector('#form')
const input = document.querySelector('#phone')
const output = document.querySelector('#output')

const re = /^(?:\d{3}|\(\d{3}\))([-\/\.])\d{4}\1\d{4}$/

function testInfo(phoneInput) {
  const ok = re.exec(phoneInput.value)

  if (!ok) {
    output.textContent = `ํ˜•์‹์— ๋งž์ง€ ์•Š๋Š” ์ „ํ™”๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. (${phoneInput.value})`
  } else {
    output.textContent = `๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ „ํ™”๋ฒˆํ˜ธ๋Š” ${ok[0]} ์ž…๋‹ˆ๋‹ค.`
  }
}

form.addEventListener('submit', (event) => {
  event.preventDefault()
  testInfo(input)
})

 

 

 

์›นํŒฉ์ด ์ž˜ ๋นŒ๋“œ๋˜์—ˆ๋Š”์ง€ ํ…Œ์ŠคํŠธ  ํ•˜๊ธฐ ์œ„ํ•ด

WordRelay.jsx ํŒŒ์ผ์„ ๊ณ ์ณ๋ณด์ž.

 

const React = require("react");
const { Component } = React;

class WordRelay extends Component {
  state = {
    text: "Hello Webpack",
  };

  render() {
    return <h1>{this.state.text}</h1>;
  }
}

module.exports = WordRelay;

 

์‹คํ–‰ ๊ฒฐ๊ณผ (index.html)

 

 

+) ์ฐธ๊ณ ๋กœ, app.js ๋ณด๋ฉด ์ฝ”๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜์–ด์žˆ์Œ.

 

- ์›นํŒฉ์ด client.jsx๋ž‘ WordRelay.jsx๋ฅผ ํ•ฉ์ณ์„œ app.js ์•ˆ์— ๋‚ด์šฉ์„ ๋งŒ๋“ ๊ฒƒ์ž„!

 

 


 

์‘์šฉ ์˜ˆ์ œ

- ์ง€๋‚œ๋ฒˆ ์˜ˆ์ œ์˜€๋˜ ๊ตฌ๊ตฌ๋‹จ ๊ฒŒ์ž„์„ ์›นํŒฉ์œผ๋กœ ๋นŒ๋“œํ•ด๋ณด์ž!

 

 

์ง€๊ธˆ๊นŒ์ง€์˜ ๊ณผ์ •๋Œ€๋กœ

 

1. npm init

2. npm i react, react-dom

3. npm i -D webpack webpack-cli

4. npm i -D babel-loader @babel/core @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties

 

 

 

5. webpack.config.js ์„ค์ •ํ•˜๊ธฐ

- name / mode / devtool

- resolve - extensions: .js, .jsx

 

- entry

app: "./client"

 

- module

test

loader

options - presets

 

- output

- path: path.join(__dirname, "dist")

- filename : 'app.js'

 

 

 

6. GuGuDan.jsx ์ƒ์„ฑ

 

- ์ง€๋‚œ๋ฒˆ์— ์ž‘์„ฑํ–ˆ๋˜ ๊ฒƒ ํ™•์žฅ์ž๋ช…๋งŒ ๋ฐ”๊พธ๊ณ ,

- react require๋กœ ๊ฐ€์ ธ์˜ค๊ณ ,

- module.exports = GuGuDan

 

+) ์—ฌ๊ธฐ์„œ React.useState์™€ React.useRef๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ

๊ตฌ์กฐ๋ถ„ํ•ด ๋ฌธ๋ฒ•์œผ๋กœ ๋‘˜์„ ์„ ์–ธํ•ด์คŒ.

 

>> ์›๋ž˜ ๋ณธ๋ฌธ์—์„œ 

const [first, setFirst] = React.useState(''); ์ด๋Ÿฐ์‹์œผ๋กœ ์จ์ฃผ๋˜๊ฑธ

const [first, setFirst] = useState(''); ๋ผ๊ณ ๋งŒ ํ•ด์ค˜๋„ ๋œ๋‹ค.

 

 

const React = require("react");
const { useState, useRef } = React;

const GuGuDan = () => {
  const [first, setFirst] = useState(Math.ceil(Math.random() * 9));
  const [second, setSecond] = useState(Math.ceil(Math.random() * 9));
  const [value, setValue] = useState("");
  const [result, setResult] = useState("");

  let inputRef = useRef(null);

  const onFormSubmit = e => {
    e.preventDefault();
    if (parseInt(value) === first * second) {
      setResult(prevResult => {
        return "์ •๋‹ต์ž…๋‹ˆ๋‹ค! " + value;
      });
      setFirst(Math.ceil(Math.random() * 9));
      setSecond(Math.ceil(Math.random() * 9));
      setValue("");
      inputRef.current.focus();
    } else {
      setResult("โŒ ์˜ค๋‹ต์ž…๋‹ˆ๋‹ค");
      setValue("");
      inputRef.current.focus();
    }
  };

  const onInputChange = e => {
    setValue(e.target.value);
  };

  return (
    <>
      <h1>๐Ÿ’ฏ๊ตฌ๊ตฌ๋‹จ ๊ฒŒ์ž„๐Ÿ’ฏ</h1>
      <div>
        ๐Ÿ“ƒ {first} ๊ณฑํ•˜๊ธฐ {second} ๋Š”?
      </div>
      <form onSubmit={onFormSubmit}>
        <input
          ref={inputRef}
          type="number"
          required
          placeholder="์ •๋‹ต ์ž…๋ ฅ"
          value={value}
          onChange={onInputChange}
        />
        <button type="submit">์ž…๋ ฅ</button>
      </form>
      <div>{result}</div>
    </>
  );
};

module.exports = GuGuDan;

 

 

7. ์ด์ œ $npx webpack์ด๋ผ๊ณ  ์น˜๊ฑฐ๋‚˜, package.json์—์„œ scripts ๋ถ€๋ถ„์— 

  "scripts": {
    "dev": "webpack"
  },

์œ„์™€๊ฐ™์ด ์„ ์–ธํ–ˆ์œผ๋ฏ€๋กœ, 

$npm run dev ๋ผ๊ณ  ์ณ๋„ ๋œ๋‹ค.

 

 

 

 

์›นํŒฉ์œผ๋กœ ์ž˜ ๋นŒ๋“œํ–ˆ๋‹ค.

 

 

์ฐธ๊ณ  - ๋‚œ ๋‹น์—ฐํžˆ ./dist/app.js๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋†“๊ณ  (๋นˆํŒŒ์ผ)

npx webpack์„ ํ–ˆ๋Š”๋ฐ, ๊ทธ๋ƒฅ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

 

 

 

๐Ÿ“ ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ตฌ์กฐ

 

index.html์€ ๋ฐ˜๋“œ์‹œ ์žˆ์–ด์•ผํ•˜๊ณ 

 

client.jsx๋Š” ์—”ํŠธ๋ฆฌ์šฉ. (entry๋Š” ๋ณดํ†ต client.jsx๋กœ)

๊ทธ๋ฆฌ๊ณ  ./dist/app.js๋Š” output์šฉ.

 

๋ชจ๋“  jsxํŒŒ์ผ์„ ํ•ฉ์ณ์„œ app.js๋ฅผ ๋งŒ๋“ค๊ณ ,

๊ทธ๊ฑธ index.html์— script:src๋กœ ์—ฐ๊ฒฐํ•˜์ž.

 

 

 

 


 

์ฐธ๊ณ 

 

 

๐Ÿ”ง webpack.config.js 

  module: {
    rules: [
      {
        test: /\.jsx?/,
        loader: "babel-loader",
        options: {
          presets: ["@babel/preset-env", "@babel/preset-react"],
        },
      },
    ],
  },

 

์ด๋ถ€๋ถ„์„ ๋ณด๋ฉด,

loader๊ฐ€ babel-loader์ด๊ณ , ๊ทธ์— ํ•ด๋‹นํ•˜๋Š” options๊ฐ€ presets ๋ถ€๋ถ„์— ํ•ด๋‹นํ•œ๋‹ค.

๋งŒ์•ฝ, @babel/preset-env์— ๋Œ€ํ•œ ์„ค์ •์ด ๋˜ ํ•„์š”ํ•˜๋‹ค๋ฉด??

 

** preset์ด๋ž€, ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค์˜ ๋ชจ์Œ์ด๋‹ค.

 

 options: {
          presets: [
            [
              "@babel/preset-env", {
               targets: {
                  browsers: ["last 2 chrome versions"],
                },
                debug: true,
            ],
            "@babel/preset-react",
          ],
        },

์ด๋Ÿฐ์‹์œผ๋กœ ํ•ด๋‹น preset์„ ๋ฐฐ์—ด๋กœ ๊ฐ์‹ธ์ฃผ๊ณ ,

์ฒซ๋ฒˆ์งธ ์š”์†Œ๋กœ๋Š” ์ด๋ฆ„์„ ์ ์–ด์ฃผ๊ณ 

๋‘๋ฒˆ์งธ ์š”์†Œ๋กœ option์„ ์ ์–ด์ฃผ๋ฉด ๋œ๋‹ค.

 

์—ฌ๊ธฐ์„œ๋Š” preset-env์˜ ์˜ต์…˜ ์ค‘ ํ•˜๋‚˜๋กœ, target - browser์„ ์ด์šฉํ–ˆ๋‹ค.

(ํฌ๋กฌ์˜ ์ตœ์‹  2๋ฒ„์ „๊นŒ์ง€๋งŒ ํ˜ธํ™˜๋˜๋„๋ก)

 

 

๐Ÿ”ป [์ฐธ๊ณ ] ๋ธŒ๋ผ์šฐ์ € ๋ฆฌ์ŠคํŠธ (target)

 

GitHub - browserslist/browserslist: ๐Ÿฆ” Share target browsers between different front-end tools, like Autoprefixer, Stylelint a

๐Ÿฆ” Share target browsers between different front-end tools, like Autoprefixer, Stylelint and babel-preset-env - GitHub - browserslist/browserslist: ๐Ÿฆ” Share target browsers between different front-en...

github.com

 

 

์ถ”๊ฐ€๋กœ, plugins๋Š” 

module์˜ option์— preset๊ณผ ํ•จ๊ป˜ ์ผ์—ˆ๋Š”๋ฐ,

plugins: [new webpack.LoaderOptionsPlugin({ debug: true })],

 

์ด๋Ÿฐ์‹์œผ๋กœ ๋‹จ๋…์œผ๋กœ ์จ๋„ ๋œ๋‹ค.

module.exports = {
  mode: "development", // ์‹ค์„œ๋น„์Šค์—์„  'production'์œผ๋กœ
  devtool: "eval", // ๋น ๋ฅด๊ฒŒ
  resolve: {
    extensions: [".js", ".jsx"],
  },

  entry: {
    app: ["./client"],
  },

  module: {
    rules: [
      {
        
          // ์ƒ๋žต
               
  },

  plugins: [new webpack.LoaderOptionsPlugin({ debug: true })],   // ๐Ÿ‘ˆ๐Ÿ‘ˆ ์ด ์œ„์น˜์—

  output: {
    path: path.join(__dirname, "dist"),
    filename: "app.js",
  },
};

 

- ์ฐธ๊ณ ๋กœ, webpack์˜ LoaderOptions์˜ plugin์— ์ „๋ถ€ debug๋ฅผ true๋ฅผ ์ฃผ๋Š”๊ฒƒ์ž„.

const { webpack } = require("webpack");

+) 

์ž๋™์œผ๋กœ ์ด๋ ‡๊ฒŒ webpack์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ฝ”๋“œ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

(new webpack ๋ถ€๋ถ„ ์ฃผ๋ชฉ)

 

 

 

* ์ง€๊ธˆ๊นŒ์ง€์˜ ์ฝ”๋“œ

 

๐Ÿ“ƒ webpack.config.js

const path = require("path");
const { webpack } = require("webpack");

module.exports = {
  mode: "development", // ์‹ค์„œ๋น„์Šค์—์„  'production'์œผ๋กœ
  devtool: "eval", // ๋น ๋ฅด๊ฒŒ
  resolve: {
    extensions: [".js", ".jsx"],
  },

  entry: {
    app: ["./client"],
  },

  module: {
    rules: [
      {
        test: /\.jsx?/,
        loader: "babel-loader",
        options: {
          presets: [
            [
              "@babel/preset-env",
              {
                targets: {
                  browsers: ["last 2 chrome versions"],
                },
                debug: true,
              },
            ],
            "@babel/preset-react",
          ],
        },
      },
    ],
  },

  output: {
    path: path.join(__dirname, "dist"),
    filename: "app.js",
  },
};

 

์ฐธ๊ณ  - LoaderOptionsPlugin ์ด๋ถ€๋ถ„์ด ์—๋Ÿฌ๊ฐ€ ๋‚˜์„œ

(์•„๋งˆ ์›นํŒฉ ๋ฒ„์ „ ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ์ธ๋“ฏ)

๊ทธ๋ƒฅ ๋นผ๋ฒ„๋ฆฌ๋ผ๊ณ  ํ•ด์„œ ๋บ๋‹ค.

 

 

 

 

 

+)

 

$ npm run dev ํ•ด๋ณด๋ฉด ์ด๋Ÿฐ์‹์œผ๋กœ ๋œฌ๋‹ค

@babel/preset-env: `DEBUG` option

Using targets:
{
  "chrome": "98"
}

 

 

 

 

 

 

Webpack ๊ณต์‹ Doc.

 

 

Concepts | webpack

webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

webpack.js.org

 

 

 

์›นํŒฉ์ด ๊ฐ•์กฐํ•œ ๊ฐœ๋…์€ ํฌ๊ฒŒ ๋‹ค์„ฏ๊ฐ€์ง€.

- entry

- output

- loaders

- plugins

- mode

 

 

โ— ์›นํŒฉ ์„ค์ • ์ž‘์„ฑํ• ๋•Œ TIP

 

entry - module - plugins - output ์ˆœ์œผ๋กœ ์ž‘์„ฑํ•˜๋ฉด ์‰ฌ์›€.

(ํ๋ฆ„์— ๋”ฐ๋ผ์„œ)

 

entry์— ์žˆ๋Š” ํŒŒ์ผ์— module ์ ์šฉํ•˜๊ณ , plugin๋„ ์ถ”๊ฐ€์ ์œผ๋กœ ์ ์šฉํ•˜๊ณ 

output์œผ๋กœ ๋‚˜์˜ด.