개발노트

npm명령어 두개 한번에 동시 실행하기 본문

Node js/npm

npm명령어 두개 한번에 동시 실행하기

aloha2jh 2021. 7. 19. 15:17

terminal 관련 package (npm-run-all, ttab)

"scripts": {
    "dev": "run-s tab:json-server serve",
    "serve": "nuxt --open",
    "build": "nuxt build",
    "start": "nuxt start",
    "tab:json-server": "ttab -w json-server --watch fake-server/db.json --port 3001"
  },

npm run dev  명령어 입력으로. dev에 작성된 (띄어쓰기구분으로) 두개의 명령실행가능.

(원래 npm run dev 하고

터미널창을 하나 더켜서 json-server --watch fake-server/db.json --port 3001" 명령어를 입력하고 있었다.)

 

npm run tab:json-server

npm run serve 

 

 

npm-run-all 

명령어 여러개 입력가능

 

ttab

새로운 윈도우창으로 (json-server)실행 가능.

 

ttab + npm-runall (예제 동영상)

https://egghead.io/lessons/npm-open-multiple-terminal-tabs-on-npm-start-with-ttab-and-npm-run-all

 

npm-run-all > run-s 

https://github.com/mysticatea/npm-run-all/blob/master/docs/run-s.md

 


새 terminal 열려고 설치한 ttab 패키지 기능이 --parallel 명령어로 대체가능해서 아래와 같이 수정

 

"scripts": {
    "dev": "npm-run-all --parallel run:json-server serve",
    "serve": "nuxt --open",
    "build": "nuxt build",
    "start": "nuxt start",
    "run:json-server": "json-server --watch fake-server/db.json --port 3001"
  },

 


"scripts": {
    "dev": "npm-run-all --parallel run:json-server run:backend-server serve",
    "serve": "nuxt --open",
    "build": "nuxt build",
    "start": "nuxt start",
    "lint": "eslint --ext \".js,.vue\" --ignore-path .gitignore",
    "run:json-server": "json-server --watch fake-server/db.json --port 3001",
    "run:backend-server":"npm run dev --prefix back-end",
    "test": "jest --watchAll"
  },

"run:backend-server" :"npm run dev --prefix back-end"

=> back-end 디렉토리로 이동하여 npm run dev 실행

 

npm run dev 실행시 run:back-endserver 명령어도 같이 실행시켜줌~~

'Node js > npm' 카테고리의 다른 글

express-generator  (0) 2021.10.14