본문 바로가기
개발 환경/GitHub

[Github] MAC 로컬에서 private 레파지토리를 npm_modules에서 사용하기

by 우주다람쥐 2020. 11. 29.
반응형

github에서 레파지토리를 만들고, 사용하다보면 특정 부분을 분리하여 npm_modules로 사용하고 싶을 때가 있다.

public 같은 경우, package.json에 추가해서 사용하면 되지만 private 레파지토리는 그런 방법으로는 다운로드가 되지 않는다.

 

그럴 경우 로컬 환경에서 npm install을 이용하여 private 레파지토리를 다운받는 방법은 다음과 같다.

 

1. 먼저 터미널에서 SSH key를 만들어준다.

만드는 방법은 아래의 링크를 참고하자

 

docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

 

Generating a new SSH key and adding it to the ssh-agent - GitHub Docs

Generating a new SSH key and adding it to the ssh-agent After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent. Mac Windows Linux All If you don't already have an SSH key, you must

docs.github.com

 

 

2. SSH key를 성공적으로 만들었다면 github 계정에 추가해준다.

추가하는 방법은 아래의 링크를 참고하자

 

docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

 

Adding a new SSH key to your GitHub account - GitHub Docs

Adding a new SSH key to your GitHub account To configure your GitHub account to use your new (or existing) SSH key, you'll also need to add it to your GitHub account. Mac Windows Linux All Before adding a new SSH key to your GitHub account, you should have

docs.github.com

 

3. github 계정에 SSH key를 추가했다면 package.json에 연동하고 싶은 private 레파지토리를 연동한다.

// package.json
...
"dependencies": {
 "{npm_module_name}": "git+ssh://git@github.com:{github_user_name}/{github_repo_name}.git",
 ...
}
...

이때, dependencies에 추가하든 devDependencies에 추가하든 상관없다.

만드는 거에 따라 알아서 설정해준다.

 

모든 과정이 끝나면 npm 모듈을 설치해준다.

$ npm install

 

정상적으로 설치되는 것을 확인할 수 있다.

가장 처음에 설치할 때는 SSH key 관련해서 확인을 하느라 시간이 조금 더 걸리니, 여유있게 기다리도록 한다.

 

4. 설치가 잘 되었다면 private 레파지토리를 npm_modules처럼 연동해서 사용하면 된다.

const privateRepo = require('privateRepo');

 

반응형

댓글