Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

kohigowild

JavaScript ES6 ๋ชจ๋“ˆ ๋ณธ๋ฌธ

JavaScript

JavaScript ES6 ๋ชจ๋“ˆ

kohi โ˜• 2022. 10. 29. 16:09

๐Ÿง ๋ชจ๋“ˆ์ด๋ž€?


ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋ชจ๋“ˆ์ด๋ž€ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ตฌ์„ฑ ์š”์†Œ์˜ ์ผ๋ถ€์ด๋‹ค.

ํ”„๋กœ๊ทธ๋žจ์˜ ํฌ๊ธฐ๊ฐ€ ์ปค์ง€๋ฉด ํ™•์žฅ์„ฑ๊ณผ ์œ ์ง€ ๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ ํŒŒ์ผ์„ ์—ฌ๋Ÿฌ ๊ฐœ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ์‹œ์ ์ด ์˜ค๋Š”๋ฐ, ์ด๋•Œ ๋ถ„๋ฆฌ๋œ ํŒŒ์ผ ๊ฐ๊ฐ์„ ‘๋ชจ๋“ˆ’ ์ด๋ผ ๋ถ€๋ฅด๊ณ , ๋ณดํ†ต ํด๋ž˜์Šค ํ•˜๋‚˜ ํ˜น์€ ํŠน์ •ํ•œ ๋ชฉ์ ์„ ๊ฐ€์ง„ ๋ณต์ˆ˜์˜ ํ•จ์ˆ˜๋กœ ๊ตฌ์„ฑ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ•˜๋‚˜๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

ํ”„๋กœ๊ทธ๋žจ์„ ์ž˜๊ฒŒ ์ชผ๊ฐœ์–ด ๋ชจ๋“ˆํ™”ํ•˜๋Š” ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • ํ”„๋กœ๊ทธ๋žจ์˜ ํšจ์œจ์ ์ธ ๊ด€๋ฆฌ ๋ฐ ์„ฑ๋Šฅ ํ–ฅ์ƒ
  • ์ „์ฒด์ ์ธ ์†Œํ”„ํŠธ์›จ์–ด ์ดํ•ด์˜ ์šฉ์ด์„ฑ ์ฆ๋Œ€ ๋ฐ ๋ณต์žก์„ฑ ๊ฐ์†Œ
  • ์†Œํ”„ํŠธ์›จ์–ด ๋””๋ฒ„๊น…, ํ…Œ์ŠคํŠธ, ํ†ตํ•ฉ, ์ˆ˜์ • ์‹œ ์šฉ์ด
  • ๊ธฐ๋Šฅ์˜ ๋ถ„๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ณ  ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋‹จ์ˆœ
  • ์˜ค๋ฅ˜์˜ ํŒŒ๊ธ‰ ํšจ๊ณผ๋ฅผ ์ตœ์†Œํ™”
  • ๋ชจ๋“ˆ ์žฌ์‚ฌ์šฉ์œผ๋กœ ๊ฐœ๋ฐœ๊ณผ ์œ ์ง€ ๋ณด์ˆ˜ ์šฉ์ด

 

๐Ÿง ๋ชจ๋“ˆ์˜ ์ข…๋ฅ˜


์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” CommonJS, AMD, UMD, ESM๊ณผ ๊ฐ™์€ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๊ฐ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŠน์ง•์ด ์žˆ๋‹ค.

  • CommonJS
    • ์„œ๋ฒ„ ์‚ฌ์ด๋“œ์—์„œ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋™๊ธฐ์ ์œผ๋กœ ์ž‘๋™
    • require ๋ฌธ๋ฒ• ์‚ฌ์šฉ
  • AMD
    • ์„œ๋ฒ„ ์‚ฌ์ด๋“œ์™€ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ๋˜๋ฉฐ, ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ž‘๋™
    • define - require ๋ฌธ๋ฒ• ์‚ฌ์šฉ
  • UMD
    • CommonJS์™€ AMD๋ฅผ ๋ชจ๋‘ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ตฌํ˜„ ํŒจํ„ด
  • ESM
    • ์–ธ์–ด ์ž์ฒด์— ํ‘œ์ค€์œผ๋กœ ํƒ‘์žฌ๋œ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ
    • export - import ๋ฌธ๋ฒ• ์‚ฌ์šฉ

 

example CommonJS

math.js ⇒

exports function sum(a, b) { return a + b; }

app.js ⇒

const math = require("./math.js") 
math.sum(1, 2) // 3

exports ํ‚ค์›Œ๋“œ๋กœ ๋ชจ๋“ˆ์„ ๋งŒ๋“ค๊ณ  require() ํ•จ์ˆ˜๋กœ ๋ถˆ๋Ÿฌ๋“ค์ด๋Š” ๋ฐฉ์‹์ด๋‹ค. ๋ชจ๋“ˆํ™”๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์„ธ ๋ถ€๋ถ„์œผ๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค.

  • ์Šค์ฝ”ํ”„(Scope): ๋ชจ๋“  ๋ชจ๋“ˆ์€ ์ž์‹ ๋งŒ์˜ ๋…๋ฆฝ์ ์ธ ์‹คํ–‰ ์˜์—ญ์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  • ์ •์˜(Definition): ๋ชจ๋“ˆ ์ •์˜๋Š” exports ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•œ๋‹ค.
  • ์‚ฌ์šฉ(Usage): ๋ชจ๋“ˆ ์‚ฌ์šฉ์€ require ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ๋‹ค.

 

example AMD

html ⇒

<!DOCTYPE html>
<html lang="ko">
<head>
  <title>Document</title>
</head>
<body>
  <!-- data-main="require๊ฐ€ ๋กœ๋“œ๋œ ํ›„ ์‹คํ–‰๋  ํŒŒ์ผ" src="requireJS์—์„œ ๋น„๋™๊ธฐ๋กœ ์‚ฌ์šฉํ•  ํŒŒ์ผ" -->
  <script data-main="index.js" src="require.js"></script>
</body>
</html>

index.js ⇒

require.config({
  // ๊ธฐ๋ณธ ๊ฒฝ๋กœ
  baseUrl: '/',
  // ๋ชจ๋“ˆ์— ํ•ด๋‹นํ•˜๋Š” ๊ฒฝ๋กœ
  paths: {
    searchModule: 'searchModule',
    loaderModule: 'loaderModule',
}});

// ์ฒซ๋ฒˆ์งธ ์ธ์ž์— ํ•ด๋‹นํ•˜๋Š” ๋ชจ๋“ˆ์ด ๋กœ๋“œ๋˜์—ˆ์„ ๊ฒฝ์šฐ a๋กœ ๋ฐ›์•„์„œ getWord() ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ์ฝœ๋ฐฑํ•จ์ˆ˜ ์‹คํ–‰
// ์˜์กด์„ฑ ๋ชจ๋“ˆ์„ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ
require(['searchModule'], (searchModule) => {
	searchModule.getWord();
});

searchModule.js ⇒

define(() => {
  return {
  	getWord: () => 'word'
  }
});

 

example UMD
(function (root, factory) {

    // AMD
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define([], factory);

    // CommonJS
    } else if (typeof module === 'object' && module.exports) {
        // Node. Does not work with strict CommonJS, but
        // only CommonJS-like environments that support module.exports,
        // like Node.
        module.exports = factory();

    // Browser
    } else {
        // Browser globals (root is window)
        root.returnExports = factory();

}}(typeof self !== 'undefined' ? self : this, function () {
    // Just return a value to define the module export.
    // This example returns an object, but the module
    // can return a function as the exported value.
    return {};
}));

 

๐Ÿง ESM


ESM์€ ES6๋ถ€ํ„ฐ ์ง€์›ํ•˜๊ณ  ์žˆ๋Š” ํ‘œ์ค€ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ์ด๋‹ค. ES6 ์ด์ „๊นŒ์ง€๋Š” ๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ‘œ์ค€ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ์ด ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, ํ•„์š”ํ•œ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ๊ฐ™์ด ๋ฐฐํฌํ•˜๊ณ , <script src=”script.js”>์˜ ํ˜•ํƒœ๋กœ ํŒŒ์ผ์„ ์ง์ ‘ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ–ˆ๋‹ค.

export

export๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ named export์™€ default export์˜ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹๊ณผ export์™€ from์„ ์กฐํ•ฉํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด ์žˆ๋‹ค.

 

named export

named export๋Š” ์„ ์–ธ๋œ ๋ณ€์ˆ˜๋ช…์„ ๊ทธ๋Œ€๋กœ exportํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. named export๋Š” ๋ชจ๋“ˆ ๋‚ด์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ export๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ๊ณ , ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•จ๊ณผ ๋™์‹œ์— ๋‚ด๋ณด๋‚ด๊ธฐ๋ฅผ ํ•˜๊ฑฐ๋‚˜, ๋จผ์ € ์ •์˜๋œ ๋ณ€์ˆ˜๋ฅผ ๋ชจ์•„์„œ ๋‚ด๋ณด๋‚ด๊ณ , ๋จผ์ € ์ •์˜๋œ ํ•จ์ˆ˜๋ฅผ ๋ณ„์นญ์œผ๋กœ ๋ฐ”๊ฟ”์„œ ๋‚ด๋ณด๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค.

export let name1;
export const name2;
export var name3;
export function name4 () {/*...*/}
export class MyClass {/*...*/}
const var1;
let var2;
var var3;
export { var1, var2, var3 }
let var4;
export { var4 as var5 }

 

default export

default export๋Š” ๋ชจ๋“ˆ์—์„œ ํ•˜๋‚˜๋งŒ ์กด์žฌํ•  ์ˆ˜ ์žˆ๊ณ , named export์™€ ๊ฐ™์ด ๋ณ€์ˆ˜๋ฅผ ์ง์ ‘ ๋‚ด๋ณด๋‚ผ ์ˆ˜๋Š” ์—†๋‹ค. default export๋ฅผ default export {const, let, var} ์ฒ˜๋Ÿผ ๋ณ€์ˆ˜๋ฅผ ์ง์ ‘ ๋‚ด๋ณด๋‚ด๋Š” ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

export default expression;
export default function () { /*...*/ }
export default function myFunction() { /*...*/ }
export default class { /*...*/ }
export default class MyClass { /*...*/ }
export default function* () { /*...*/ }

const myModule = { /*...*/ }
const var1 = () => {}
export { myModule as default, var1 }
export default function () { /*...*/ }
export default MyClass () { /*...*/ }
Uncaught SyntaxError: Identifier '*default*' has already been declared

export default๋ฅผ ๋‘ ๋ฒˆ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋„ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. default๋ผ๋Š” ์‹๋ณ„์ž๋ฅผ export ๋ฌธ์ด ๋‚ด๋ถ€์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

export from

export from์€ import์™€ export๋ฅผ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ๋ฒ•์ด๋‹ค. ์ฃผ๋กœ ํŒจํ‚ค์ง€์˜ ๋‹ค๋ฅธ ๋ชจ๋“ˆ๋“ค์„ ํ•œ ๋ฒˆ์— ๋ชจ์•„์„œ ์ผ๊ด€๋œ ํ˜•ํƒœ๋กœ ๋‚ด๋ณด๋‚ด๊ฑฐ๋‚˜ ๊ด€๋ฆฌํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•œ๋‹ค.

export from ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด import์™€ export๋ฅผ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ์ง€๋งŒ, ๋‹คexport-from์„ ์ฒ˜๋ฆฌํ•˜๋Š” ํŒŒ์ผ ์Šค์ฝ”ํ”„์—์„œ๋Š” ์‹๋ณ„์ž๊ฐ€ ๋ฐ”์ธ๋”ฉ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”์„œ๋“œ๋‚˜ ๋ณ€์ˆ˜์— ์ง์ ‘ ์ ‘๊ทผํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ์—๋Ÿฌ ๋ฐœ์ƒ ์ด์œ ๋Š” ํ•ด๋‹น ๋ฉ”์„œ๋“œ๊ฐ€ ์Šค์ฝ”ํ”„ ๋‚ด์— ์กด์žฌํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ.

๋‹ค์Œ๊ณผ ๊ฐ™์ด index.js math.js logger.js config.js ๋ชจ๋“ˆ์„ ํฌํ•จํ•˜๋Š” src/utils ํŒจํ‚ค์ง€๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ,

export function add (a, b) { /*...*/ }
export function subtract (a, b) { /*...*/ }
export function multiply (a, b) { /*...*/ }
export function divide (a, b) { /*...*/ }
export default {
  print() { /*...*/ }
}
export const DB_HOST = 'localhost';
export const DB_USER = 'scott';
export const DB_PASSWORD = 'tiger';

src/utils ํŒจํ‚ค์ง€์— ์žˆ๋Š” src/utils/index.js์—์„œ๋Š” export-from ๋ฌธ๋ฒ•์„ ๋‹ค์Œ์ฒ˜๋Ÿผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๊ณ , src/utils/index.js์—์„œ export๋œ ๋ชจ๋“ˆ์€ src/index.js์—์„œ import ๋ช…๋ น์–ด๋กœ ๋ถˆ๋Ÿฌ์™€์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

// math ๋ชจ๋“ˆ์—์„œ ์ผ๋ถ€๋งŒ import ํ•œ ๋’ค ๋‹ค์‹œ export
export { add, subtract } from './math';
// config ๋ชจ๋“ˆ์˜ (export๊ฐ€ ๊ฐ€๋Šฅํ•œ) ๋ชจ๋“  ๋ณ€์ˆ˜๋ฅผ export
export * from './config';
// logger ๋ชจ๋“ˆ์˜ default export๋ฅผ Logger๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ export
export { default as Logger } from './logger';
// ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ importํ•˜๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ index.js ํŒŒ์ผ์„ ํƒ์ƒ‰ํ•จ
import * as utils from './utils';
// utils๋ผ๋Š” ๋ณ„์นญ์œผ๋กœ importํ•œ ๋ฉ”์†Œ๋“œ, ๋ณ€์ˆ˜ ์‚ฌ์šฉ
utils.add(1, 2) // 3
utils.DB_HOST // 'localhost'
utils.Logger.print('TEST') // 'TEST'

 

import

import๋Š” ๋‹ค๋ฅธ ํŒŒ์ผ์—์„œ ๋ชจ๋“ˆ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ช…๋ น์–ด์ด๋‹ค. as ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ ๋ณ„์นญ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค๊ฑฐ๋‚˜, *๋ฅผ ์‚ฌ์šฉํ•ด์„œ named export์˜ ๋ชจ๋“  ๋ณ€์ˆ˜์™€ ๋ฉ”์„œ๋“œ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

import name from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1 , member2 } from "module-name";
import { member1 , member2 as alias2 , [...] } from "module-name";
import defaultMember, { member [ , [...] ] } from "module-name";
import defaultMember, * as alias from "module-name";
import defaultMember from "module-name";
import "module-name";

 

๐Ÿง Module Type


<script> ํƒœ๊ทธ์— type = “module” ์„ ์„ ์–ธํ•˜๋ฉด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์€ ๋ชจ๋“ˆ๋กœ ๋™์ž‘ํ•˜๊ฒŒ ๋œ๋‹ค. ESM์€ ECMAScript์—์„œ ์ง€์›ํ•˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ณต์‹ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ์ด์ง€๋งŒ, ๋ธŒ๋ผ์šฐ์ €์— ๋”ฐ๋ผ์„œ๋Š” ์•„์ง import์™€ export๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์–ด์„œ ๊ฐ€๋Šฅํ•˜๋ฉด webpack๊ณผ ๊ฐ™์€ ๋ฒˆ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

 

๐Ÿง Webpack


์›นํŒฉ์€ ์˜คํ”ˆ ์†Œ์Šค ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ชจ๋“ˆ ๋ฒˆ๋“ค๋Ÿฌ๋กœ์จ ์—ฌ๋Ÿฌ ๊ฐœ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ ํ•˜๋‚˜์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋กœ ์••์ถ•ํ•˜๊ณ  ์ตœ์ ํ™”ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

๋ชจ๋“ˆ ๋ฒˆ๋“ค๋Ÿฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์ ์ด ์žˆ๋‹ค.

  • ์—ฌ๋Ÿฌ ํŒŒ์ผ์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์••์ถ•ํ•˜์—ฌ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋กœ๋”ฉ์— ๋Œ€ํ•œ ๋„คํŠธ์›Œํฌ ๋น„์šฉ ๊ฐ์†Œ
  • ์ตœ์‹  ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฌธ๋ฒ•์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๋กœ ์‰ฝ๊ฒŒ ๋ณ€ํ™˜

์›นํŒฉ์€ entry๋กœ ์„ค์ก๋œ ์‹œ์ž‘์ ์—์„œ ์˜์กด์„ฑ์„ ๊ฐ€์ง„ ๋ชจ๋“  ํŒŒ์ผ์„ ์••์ถ•ํ•˜์—ฌ output ์ง€์ ์— ํ•˜๋‚˜์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ์ค€๋‹ค. ์ด๋•Œ, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์•„๋‹Œ ํŒŒ์ผ์€ loaders๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ์ด์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“ˆ๋กœ ๋งŒ๋“ค์–ด ์ฃผ๋ฉฐ, plugins๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฒˆ๋“ค๋œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‚œ๋…ํ™”ํ•˜๊ฑฐ๋‚˜ ํŠน์ • ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. mode๋Š” ์›นํŒฉ์˜ ์‚ฌ์šฉ ๋ชฉ์ ์— ๋”ฐ๋ผ ์„ค์ •์„ ์ง€์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

๐Ÿง Reference


https://medium.com/@woody_dev/js-webpack-1-์›นํŒฉ์ด๋ž€-๋ฌด์—‡์ธ๊ฐ€-f29ebca31da4

https://wormwlrm.github.io/2020/08/12/History-of-JavaScript-Modules-and-Bundlers.html

https://www.daleseo.com/js-module-import/

https://velog.io/@syoung125/๊ฐœ๋…๊ณต๋ถ€-1.-Javascript

https://www.zerocho.com/category/JavaScript/post/5b67e7847bbbd3001b43fd73

https://www.youdad.kr/js-module-system/

https://okayoon.tistory.com/entry/์•„ํ‹ฐํด-ํ”„๋กœ์ ํŠธ-059-๋ชจ๋“ˆ-์‹œ์Šคํ…œ-CommonJS-AMD-UMD-ES6