Skip to content

Instantly share code, notes, and snippets.

@CEOmurky
Last active November 18, 2019 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CEOmurky/8a9538145724feb3ebaf74f92054b3db to your computer and use it in GitHub Desktop.
Save CEOmurky/8a9538145724feb3ebaf74f92054b3db to your computer and use it in GitHub Desktop.
node moulde을 command-line으로 사용하게끔 배포하기

typescript는 tsc를 사용해서 커맨드라인을 사용해 바로 typescript 명령어를 사용할 수 있는데 이는 npm의 bin 파일을 이용하면 가능하다.

먼저 pakcage.json에 bin을 추가해주고

// ...package.json
{
  "bin": {
    "hello": "hello.js"
  }
}
// ...hello.js
console.log('hello world');

npm link를 실행하면 pakcage.json에 기록한 bin 파일의 위치를 찾고 자동으로 bin을 추가해준다. 이를 사용해 테스트를 할 수 있고 npm publish를 통해 배포하면 자동으로 bin으로 사용할 수 있다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment