CS 및 면접 질문

package.json파일이 왜 필요한가 ?

ho-bolt 2022. 6. 26. 09:32

🦖 package.json

 

🤪  npm Docs에 써져있는 package.json

You can add a package.json file to your package to make it easy for others to manage and install. Packages published to the registry must contain a package.json file.

lists the packages your project depends on
specifies versions of a package that your project can use using semantic versioning rules
makes your build reproducible, and therefore easier to share with other developers

  • package.json은 문서
  • 개발자가 배포한 패키지에 대해 다른 사람들이 관리하고 설치하기 쉽게 하기 위한 문서
  • npm에 패키지를 배포하고, npm registry에 올리기 위해서 반드시 필요한 문서파일
    • 자신의 프로젝트가 의존하는 패키지 리스트
    • 자신의 프로젝트 버전 명시
    • 다른 환경에서도 빌드를 재생하게 만들어, 다른 개발자가 쉽게 사용하게 만듦

😝 npm이라는 오픈소스 패키지 생태계를 사용하기 위한 명세, 프로젝트의 의존성 관리를 위한 명세, 이 생태계로의 배포를 위한 명세 이다 .

⚒ 구성요소

  • json파일로 속성 - 값의 쌍으로 이루어져 있다.
🔧기본 구성 요소
$ npm init -y

이렇게 처음 기본 설정값으로 package.json을 설정하면

{
  "name": "PROJECT_DIRECTORY",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

이렇게 생기게 된다.

💡결론

결론적으로 package.json파일이 필요한 이유는 프로젝트의 이름과 버전을 명시해두어 다른 개발자들이 참고할 수 있게 해주고 다른 환경에서도 쉽게 빌드하여 쉽게 사용할 수 있게 만들기 위해 필요하다!!

 

 

 

참고 https://hoya-kim.github.io/2021/09/14/package-json/

728x90