๐Ÿ“” ๋ชจ๋“ˆ ํ•ด์„

Parcel ํ•ด์„๊ธฐ๋Š” ์ˆ˜์ •๋œ ๋ฒ„์ „์˜ node_modules ํ•ด์„ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“ˆ ํ•ด์„

ํ‘œ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์™ธ์—๋„, Parcel์—์„œ ์ง€์›ํ•˜๋Š” ์• ์…‹ ์œ ํ˜•๋„ ํ•ด์„๋ฉ๋‹ˆ๋‹ค.

๋ชจ๋“ˆ ํ•ด์„์€ ๋‹ค์Œ๊ณผ ๊ด€๋ จ๋ฉ๋‹ˆ๋‹ค.:

์ ˆ๋Œ€๊ฒฝ๋กœ

/foo๋Š” entry root์˜ ์ƒ๋Œ€์ ์ธ ๊ฒฝ๋กœ์˜ foo๋ฅผ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.

~(ํ‹ธ๋“œ) ๊ฒฝ๋กœ

~/foo๋Š” package root์˜ ์ƒ๋Œ€์ ์ธ ๊ฒฝ๋กœ์˜ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ฒฝ๋กœ๋ฅผ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋ชจ๋“ˆ์ด ์—†๋‹ค๋ฉด, entry root์—์„œ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.

Glob ํŒŒ์ผ ๊ฒฝ๋กœ

Glob ํŒŒ์ผ ๊ฒฝ๋กœ๋Š” ์—ฌ๋Ÿฌ ์• ์…‹์„ ๋ฌถ์–ด ํ•œ๊บผ๋ฒˆ์— ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” ์™€์ผ๋“œ์นด๋“œ ์ž„ํฌํŠธ์ž…๋‹ˆ๋‹ค. Glob์€ ์ผ๋ถ€ ๋˜๋Š” ๋ชจ๋“  ํŒŒ์ผ (/assets/*.png)๊ณผ ์—ฌ๋Ÿฌ ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ํŒŒ์ผ (/assets/**/*)๊ณผ ์ผ์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์€ png ํŒŒ์ผ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ฌถ์–ด dist URL์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

import foo from "/assets/*.png";
// {
//   'file-1': '/file-1.8e73c985.png',
//   'file-2': '/file-1.8e73c985.png'
// }

package.json์˜ browser ํ•„๋“œ

๋งŒ์•ฝ package์— package.browser ํ•„๋“œ๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ, Parcel์€ package.main๋Œ€์‹  ์ด ํ•ญ๋ชฉ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๋ณ„์นญ (Aliases)

๋ณ„์นญ์€ package.json ํŒŒ์ผ์— alias ํ•„๋“œ๋ฅผ ํ†ตํ•ด ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ์˜ˆ์ œ๋Š” react๋ฅผ preact๋กœ ๋ณ„์นญ์„ ์ง€์ •ํ•˜๊ณ , node_modules์— ์—†๋Š” ์ผ๋ถ€ ๋กœ์ปฌ์˜ ์‚ฌ์šฉ์ž ์ •์˜ ๋ชจ๋“ˆ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

// package.json
{
  "name": "some-package",
  "devDependencies": {
    "parcel-bundler": "^1.7.0"
  },
  "alias": {
    "react": "preact-compat",
    "react-dom": "preact-compat",
    "local-module": "./custom/modules"
  }
}

์ผ๋ถ€๋Š” Parcel์—์„œ ์‚ฌ์šฉํ•˜๊ณ , ๋‹ค๋ฅธ ์ผ๋ถ€๋Š” ์„œ๋“œํŒŒํ‹ฐ ๋„๊ตฌ ๋˜๋Š” ์ต์Šคํ…์…˜์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ, ํŠน์ˆ˜๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.:

๋ณ„์นญ์„ ์ •์˜ํ• ๋•Œ๋Š” ๋ช…์‹œ์ ์œผ๋กœ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ ํ™•์žฅ์ž๋ฅผ ์ง€์ • ํ•˜์‹ญ์‹œ์˜ค. ์ง€์ •ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ, Parcel์—์„œ ์ด๋ฅผ ์ถ”์ธกํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด์— ๋Œ€ํ•œ ์˜ˆ์ œ๋Š” JavaScript Named Exports๋ฅผ ์ฐธ๊ณ ํ•˜์‹ญ์‹œ์˜ค.

๊ณตํ†ต ์ด์Šˆ

Javascript Named Exports

๋ณ„์นญ์„ ๋งคํ•‘ํ•˜๋Š” ๊ฒƒ์€ ๋งŽ์€ ์• ์…‹ ํƒ€์ž…์—์„œ ์‚ฌ์ ์šฉ๋˜๋ฉฐ, Javascript named exports์—์„œ ํŠน๋ณ„ํžˆ ์ ์šฉ๋˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค. JS named exports๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•˜์‹ญ์‹œ์˜ค.:

// package.json
{
  "name": "some-package",
  "alias": {
    "ipcRenderer": "./electron-ipc.js" // specify file extension
  }
}

๊ทธ๋ฆฌ๊ณ  ๋ณ„์นญ์ด ๋งคํ•‘๋œ ํŒŒ์ผ์„ ๋‹ค์‹œ export ํ•ฉ๋‹ˆ๋‹ค.:

// electron-ipc.js
module.exports = require('electron').ipcRenderer

Flow์—์„œ ์ ˆ๋Œ€๊ฒฝ๋กœ ๋˜๋Š” ~๊ฒฝ๋กœ ํ•ด์„

Flow์—์„œ ์ ˆ๋Œ€๊ฒฝ๋กœ ๋˜๋Š” ~๊ฒฝ๋กœ ํ•ด์„์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ module.name_mapper๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ”„๋กœ์ ํŠธ ๊ตฌ์„ฑ์ด ์ œ๊ณต๋œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.:

package.json
.flowconfig
src/
  index.html
  index.js
  components/
    apple.js
    banana.js

๊ทธ๋ฆฌ๊ณ  ์ง„์ž…์ ์€ src/index.html ์ด๋ฉฐ, *entry root๋Š” src/ ํด๋”์ž…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋ฏ€๋กœ, ์ž„ํฌํŠธ๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ๋งคํ•‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.:

// index.js
import Apple from '/components/apple'

/components/apple์˜ ์„ ํ–‰๋œ /๋ฅผ src/๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•œ Flow ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ src/components/apple์ด ๋ฉ๋‹ˆ๋‹ค.

.flowconfig ์„ค์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค.

[options]
module.name_mapper='^\/\(.*\)$' -> '<PROJECT_ROOT>/src/\1'

<PROJECT_ROOT>๋Š” .flowconfig์˜ ์œ„์น˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” Flow์˜ ํŠน์ • ์‹๋ณ„์ž ์ž…๋‹ˆ๋‹ค.

์ฐธ๊ณ : module.name_mapper๋Š” ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ ˆ๋Œ€๊ฒฝ๋กœ ๋˜๋Š” ~๊ฒฝ๋กœ์˜ ํ•ด์„์„ ์ง€์›ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Typescript ํ•ด์„

Typescript์—์„œ๋Š” ~ ๋ชจ๋“ˆ์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด ๋ช…์‹œ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ TypeScript Module Resolution docs์„ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.

// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "~*": ["./src/*"]
    }
  }
}

๋ชจ๋…ธ๋ฆฌํฌ ํ•ด์„

๋ชจ๋…ธ๋ฆฌํฌ์™€ ํ•จ๊ป˜ ๊ถŒ์žฅ๋˜๋Š” ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.:

๊ถŒ์žฅ ์‚ฌ์šฉ:

๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ:

๋ชจ๋…ธ๋ฆฌํฌ ์‚ฌ์šฉ์ž์ด๊ณ , ์ด๋Ÿฌํ•œ ๊ถŒ์žฅ ์‚ฌํ•ญ์— ๊ธฐ์—ฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์˜ˆ์ œ์™€ ํ•จ๊ป˜ ์ด์Šˆ๋ฅผ ์ œ๊ณตํ•ด ์ฃผ์„ธ์š”.

๋ฌธ์„œ์˜ ๊ฐœ์„ ์„ ๋„์™€์ฃผ์„ธ์š”

๋น ์ง„์ ์ด ์žˆ๊ฑฐ๋‚˜ ๋ช…ํ™•ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ, ์›น ์‚ฌ์ดํŠธ ์ €์žฅ์†Œ์— ์ด์Šˆ๋ฅผ ์ œ๊ธฐํ•ด ์ฃผ์‹œ๊ฑฐ๋‚˜ ํŽ˜์ด์ง€๋ฅผ ์ˆ˜์ •ํ•ด ์ฃผ์„ธ์š”..