티스토리 뷰

WIL (What I Learned)

--save와 --save-dev

Pewww 2018. 8. 7. 13:32

그동안 각종 NPM 라이브러리들을 이용하면서 install --save와 --save-dev의 차이점을 모른 채 

주구장창 후자의 키워드만 썼었는데, 이제서야 검색을 하여 알게되었다...


일단 정리를 해보자면, 기본적으로 --save --save-dev 는 기본적으로 install 할 시 ./node_modules 디렉터리에 패키지 설치를 함과 동시에 ./package.json 업데이트 까지 같이 해준다.


여기서 어디에 패키지의 정보를 추가하느냐가 중요한데, 전자의 경우 dependencies, 후자의 경우 devDependencies 에 등록이 된다.



저런식으로 말이다.


한 가지 더 다른 점은, devDependencies 의 경우 dependencies 와 다르게 --production으로 빌드 시 해당 플러그인이 포함되지 않는다.


생각을 조금 해봤는데, --save-dev 의 뒤에 있는 dev라는 단어가 아마 development mode 혹은 development purpose 등을 의미하지 않을까 싶다.



마지막으로, NPM Documentation을 보며 정리하면 될 것 같다.

참고: https://docs.npmjs.com/files/package.json#dependencies


Dependencies


Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.


Please do not put test harnesses or transpilers in your dependencies


종속성은 패키지 이름을 버전 범위에 매핑하는 간단한 객체에 지정된다.

버전의 범위는 하나 이상의 공백으로 구분 된 설명자가 포함된 문자열이며, 종속성은 tarball 혹은 git의 URL로 식별될 수 있다.


의존성에 테스트 관련 도구나 트랜스파일러를 넣지 마라.


devDependencies


If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.


누군가 프로그램에서 모듈을 다운로드하고 사용할 계획중에 있다면, 그들은 프로그램에서 사용된 외부 테스트나 문서화 프레임워크들을 일일히 빌드할 필요가 없다.




정리를 해보자면, 앱을 실질적으로 동작하기에 필요하지 않은 것들 (Mocha와 같은 테스트를 위한 도구들 혹은 기타 등등) 은 --save-dev로, 이외는 --save 로 npm install을 하면 될 것 같다!




참고 자료

http://ohyecloudy.com/ddiary/2016/09/04/til-npm-install-save-or-save-dev/

https://stackoverflow.com/questions/22891211/what-is-the-difference-between-save-and-save-dev/31358981#31358981

https://docs.npmjs.com/files/package.json#dependencies


댓글