npm ์œˆ๋„์šฐ - ๋งฅ ํ˜ธํ™˜ ๋ฐฉ๋ฒ• (npm install cross-env)

2021. 9. 6. 16:31ใ†๐Ÿ“” TIL

 

๐Ÿ’ป ์ƒํ™ฉ

๋งฅos ์—์„œ node.js ๊ธฐ๋ฐ˜ ํ”„๋กœ์ ํŠธ ์ง„ํ–‰ ์ค‘, ํŒ€์— ์œˆ๋„์šฐ os ๋ฅผ ์“ฐ๋Š” ๋ถ„๋“ค์ด ํ•ฉ๋ฅ˜ํ–ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ํŒŒ์ผ์„ npm build ํ•˜๋Š” ๊ณผ์ •์—์„œ ์œˆ๋„์šฐos ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ถ„๋“ค๋งŒ ๋นŒ๋“œ๊ฐ€ ์ง„ํ–‰๋˜์ง€ ์•Š์•˜๋‹ค.

npm ๋ฌธ์„œ์— ์˜ํ•˜๋ฉด ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ NODE_ENV=production(or development) ์ฒ˜๋Ÿผ ์„ค์ •ํ•  ๋•Œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋ผ๊ณ  ํ•œ๋‹ค.

 

๐ŸŽ  ํ•ด๊ฒฐ

cross-env ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜์—ฌ ์–‘์ชฝ os ๋ฅผ ํ˜ธํ™˜์‹œํ‚จ๋‹ค.

์šฐ์„  ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•˜๊ณ , package.json ์˜ ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ™•์ธํ•œ๋‹ค. 

 

cross-env ๋ชจ๋“ˆ ๋งํฌ

 

 

1) cross-env ๋ชจ๋“ˆ ์„ค์น˜

npm install --save-dev cross-env

 

2) package.json ์Šคํฌ๋ฆฝํŠธ์— cross-env ์ถ”๊ฐ€

๊ณต์‹๋ฌธ์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด cross-env ๋ฅผ ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ์— ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๋‹ค.

{
  "scripts": {
    "build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
  }
}

 

ํ•„์ž๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋นŒ๋“œ ๋ช…๋ น์–ด์— ์„ค์ •ํ•ด์ฃผ์—ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ•„์š”ํ•œ ๋นŒ๋“œ ๋ช…๋ น์–ด์— ๊ฒฐ๊ตญ ๋‹ค cross-env ๋ฅผ ์ ์–ด์ค˜์•ผ ํ•  ๊ฒƒ ์ด๋‹ค.