Webpack - RLidea/dev.docs GitHub Wiki

Webpack

์šฉ๋„

  1. ๋ชจ๋“ˆ๊ด€๋ฆฌ์ˆ˜์›”ํ™”
  2. ์ž์—ฐ์ตœ์ ํ™”

์‚ฌ์šฉํ•˜๋Š” ์ด์œ  & ๋ฐฐ๊ฒฝ

  • ์ƒˆ๋กœ์šด ํ˜•ํƒœ์˜ Web Task Manager

    • ๊ธฐ์กด Web Task Manager(Gulp, Grunt)์˜ ๊ธฐ๋Šฅ + ๋ชจ๋“ˆ ์˜์กด์„ฑ ๊ด€๋ฆฌ (ex. manification์„ webpack defailt cli๋กœ ์‹คํ–‰ ๊ฐ€๋Šฅ)
      webpack -p
    
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ Code based modules ๊ด€๋ฆฌ

    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ชจ๋“ˆํ™”์˜ ํ•„์š”์„ฑ: AMD, Common js, ES6(Modules)
    • ๊ธฐ์กด ๋ชจ๋“ˆ ๋กœ๋”๋“ค๊ณผ์˜ ์ฐจ์ด์ : ๋ชจ๋“ˆ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ chunk ๋‹จ์œ„๋กœ ๋‚˜๋ˆ  ํ•„์š”ํ•  ๋•Œ ๋กœ๋”ฉ
    • ํ˜„๋Œ€์˜ ์›น์—์„œ js์˜ ์—ญํ• ์ด ์ปค์ง์— ๋”ฐ๋ผ client side์— ๋“ค์–ด๊ฐ€๋Š” ์ฝ”๋“œ๋Ÿ‰์ด ๋งŽ์•„์ง€๊ณ  ๋ณต์žกํ•ด์ง
    • ๋ณต์žกํ•œ ์›น ์•ฑ์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋ชจ๋“ˆ ๋‹จ์œ„๋กœ ๊ด€๋ฆฌํ•˜๋Š” Common js, AMD, ES6 Modules ๋“ฑ์ด ๋“ฑ์žฅ
    • ๊ฐ€๋…์„ฑ์ด๋‚˜ ๋‹ค์ˆ˜ ๋ชจ๋“ˆ ๋ฏธ๋ณ‘ํ–‰ ์ฒ˜๋ฆฌ๋“ฑ์˜ ์•ฝ์ ์„ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด Webpack์ด ๋“ฑ์žฅ
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ชจ๋“ˆํ™” ๋ฌธ์ œ๋ž€?

    • ๋ชจ๋“ˆํ™” ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ฐ™์€ ์Šค์ฝ”ํ”„์—์„œ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ์Šคํฌ๋ฆฝํŠธ ๋กœ๋”ฉ์ˆœ์„œ, ์ „์—ญ๋ณ€์ˆ˜ ์ถฉ๋Œ, ๋ณต์žก๋„์— ๋”ฐ๋ฅธ ๊ด€๋ฆฌ์ƒ์˜ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ.
    • ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด AMD๋ฐ ๊ธฐํƒ€ ๋ชจ๋“ˆ ๋กœ๋”๋“ค. Webpack์ด ๋“ฑ์žฅํ–ˆ๋‹ค.

Webpack ์˜ ์ฒ ํ•™

  • Everything is Mododule
    • ๋ชจ๋“  ์›น ์ž์›(js, css, html)์ด ๋ชจ๋“ˆ ํ˜•ํƒœ๋กœ ๋กœ๋”ฉ ๊ฐ€๋Šฅ
      require("base.css")
      require("main.js")
    
  • Load only 'what' you need and 'when' you need
    • ์ดˆ๊ธฐ์— ๋ถˆํ•„์š”ํ•œ ๊ฒƒ๋“ค์„ ๋ชจ๋‘ ๋กœ๋”ฉํ•˜์ง€ ์•Š๊ณ  ํ•„์š”ํ•  ๋–„ ํ•„์š”ํ•œ ๊ฒƒ๋งŒ ๋กœ๋”ฉํ•˜์—ฌ ์‚ฌ์šฉ

์„ค์น˜

npm i webpack -g
npm i webpack-cli -g
โš ๏ธ **GitHub.com Fallback** โš ๏ธ