๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ฐ ์–ธ์–ด/JS

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐœ๋ฐœ๋„๊ตฌ - git, npm, gulp

์ฑ… <๋Ÿฌ๋‹์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ>๋ฅผ ๊ธฐ๋ณธ์œผ๋กœ ๋ฐฐ์šด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

 

๋ชฉ์ฐจ

  • git ์‹œ์ž‘ํ•˜๊ธฐ
  • git ์ƒˆ ๋กœ์ปฌ ์ €์žฅ์†Œ, ์ƒˆ ํŒŒ์ผ, (.gitignore, README.md) ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ
  • npm ์‹œ์ž‘ํ•˜๊ธฐ
  • npm ํŒจํ‚ค์ง€ ๊ด€๋ผ
  • gulp ์‹œ์ž‘ํ•˜๊ธฐ

 

 

<git>

git ์‹œ์ž‘ํ•˜๊ธฐ

git : ํ˜•์ƒ๊ด€๋ฆฌ, ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์œผ๋กœ ์—ฌ๋Ÿฌ๋ช…์ด ๊ฐœ๋ฐœํ•  ๋•Œ

      ์ฝ”๋“œ๊ด€๋ฆฌ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด๋Š” ์‹œ์Šคํ…œ์ด๋‹ค.

 

git ๋™์ž‘ ๊ณผ์ •

 

git ์ƒˆ ๋กœ์ปฌ ์ €์žฅ์†Œ ๋งŒ๋“ค๊ธฐ

  • git-bash์‹คํ–‰
  • ์ ๋‹นํ•œ ๊ฒฝ๋กœ์— ๊ด€๋ฆฌํ•  ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ(test) -> ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ
  • ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— $git init ์ž…๋ ฅ
  • ".git" ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜๋ฉด ์™„๋ฃŒ

 

์ €์žฅ์†Œ์— ์ƒˆ ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

$ vim ํŒŒ์ผ ์ด๋ฆ„ 
# ํŒŒ์ผ ๋‚ด์šฉ ์ž‘์„ฑ

$ git add ํŒŒ์ผ ์ด๋ฆ„
$ git status
$ git commit -m "์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€ ์ž‘์„ฑ"

โ€ป git add ๋Š” ํŒŒ์ผ ์ถ”๊ฐ€๊ฐ€ ์•„๋‹ˆ๋ผ ํŒŒ์ผ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 

์ €์žฅ์†Œ์— .gitignoreํŒŒ์ผ ์ƒ์„ฑ

$vim .gitignore 

####.gitignore ํŒŒ์ผ ๋‚ด์šฉ####

# npm ๋””๋ฒ„๊ทธ ๊ธฐ๋ก
npm-debug.log*

# ํ”„๋กœ์ ํŠธ ์˜์กด์„ฑ
node_modules

# ์ž„์‹œ ํŒŒ์ผ
*.tmp
*~

###########################

$git add .gitignore
$git status
$git commit -m "Initial commit: added .gitignore."

 

์ €์žฅ์†Œ์— README.mdํŒŒ์ผ ์ƒ์„ฑ

= Learning JavaScript
= = Chapter 2: JavaScript Development Tools

In this chapter we're learning about Git and other
development tools.

 

<npm>

npm์‹œ์ž‘ํ•˜๊ธฐ

npm : Node Package Manager

node.js๋กœ ๋งŒ๋“ค์–ด์ง„ ๋ชจ๋“ˆ์„ ์›น์—์„œ ๋ฐ›์•„์„œ ์„ค์น˜ํ•˜๊ณ  ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค.

 

npm package๊ด€๋ฆฌ

  • node.js์„ค์น˜(npm๋‚ด์žฅ๋˜์–ด ์žˆ์Œ.) : https://nodejs.org/์—์„œ ์•ˆ์ • ๋ฒ„์ „ ์„ค์น˜
  • ์–ธ๋”์Šค์ฝ”์–ด : ์ฝ”๋”ฉ์„ ๋„์™€์ฃผ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งค์šฐ ์ž‘์€ ์šฉ๋Ÿ‰์— 80์—ฌ๊ฐ€์ง€์˜ function์„ ์ œ๊ณต.
#ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ(test)์— ์–ธ๋”์Šค์ฝ”์–ด ์„ค์น˜
$npm install --save underscore
  • ์ƒ์„ฑ๋œ node_modules ์šฐ์„  ์‚ญ์ œ
  • npm์€ package jsonํŒŒ์ผ๋กœ ์˜์กด์„ฑ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ, package.json์„ ์ฝ๊ณ  ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋ฅผ ์ž๋™์œผ๋กœ ์„ค์น˜ํ•จ.(์˜์กด์„ฑ : ํ”„๋กœ์ ํŠธ ์„ค์น˜ํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“ˆ)
$npm init
$npm install

 

<gulp>

๋นŒ๋“œ๋„๊ตฌ gulp : ๋ฐ˜๋ณต ์ž‘์—… ์ž๋™ํ™”ํ•ด์ฃผ๋Š” ๋„๊ตฌ

  • ์ „์—ญ์— gulp์„ค์น˜
$npm install -g gulp
  • ๋กœ์ปฌ์— gulp์„ค์น˜
$npm install --save-dev gulp
  • es6์ฝ”๋“œ๋ฅผ es5์ฝ”๋“œ๋กœ ๋ณ€ํ˜•ํ—ˆ์ฃผ๋Š” gulpfile.js ํŒŒ์ผ์ƒ์„ฑ (gulp์˜ task๋Š” pipe๋กœ ์—ฐ๊ฒฐ๋˜์žˆ์Œ.) 
#gulpfile.js

const gulp = require('gulp');
const babel = require('gulp-babel');
gulp.task('default', function() {  
  // ๋…ธ๋“œ ์†Œ์Šค  
  gulp.src("es6/**/*.js")
    .pipe(babel())
    .pipe(gulp.dest("dist"));
    
  // ๋ธŒ๋ผ์šฐ์ € ์†Œ์Šค
  gulp.src("public/es6/**/*.js")
    .pipe(babel())
    .pipe(gulp.dest("public/dist"));
});
  • ์„ค์น˜ ํ™•์ธ
$gulp

<์ง€๊ธˆ๊นŒ์ง€์˜ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ>

.git

.gitignore

#Git

package.json

node_modules

#npm

es6(es6 ์ฝ”๋“œ๋“ค ์ €์žฅ)

dist(es5 ์ฝ”๋“œ๋“ค ์ €์žฅ)

#๋…ธ๋“œ ์†Œ์Šค(์„œ๋ฒ„)

public/ es6

public/ dist

#๋ธŒ๋ผ์šฐ์ € ์†Œ์Šค

(ํด๋ผ์ด์–ธํŠธ)