package.json 파일은 Node.js 프로젝트와 npm 패키지의 핵심 매니페스트로서 메타데이터, 의존성 패키지, 실행 스크립트 및 빌드 설정을 통합 관리합니다.
기본 매니페스트 구조 (Basic Manifest Structure)
{
"name": "my-awesome-package",
"version": "1.0.0",
"description": "Production-grade utility library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"mycli": "./bin/cli.js"
},
"keywords": ["node", "api", "tools"],
"author": "Jane Doe <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
}
}
의존성 유형 및 버전 접두사 규칙 (SemVer)
{
"dependencies": {
"express": "^4.19.2",
"lodash": "~4.17.21"
},
"devDependencies": {
"eslint": "^9.0.0",
"typescript": "^5.4.5"
},
"peerDependencies": {
"react": ">=18.0.0"
},
"optionalDependencies": {
"fsevents": "^2.3.3"
}
}
1.2.3: Exact version match.^1.2.3: Compatible with version (1.x.x).~1.2.3: Patch upgrades only (1.2.x).*: Any available version.
npm 스크립트 및 환경 설정 변수 (Scripts & Config)
{
"config": {
"port": "8080"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc -p tsconfig.build.json",
"start": "node dist/index.js",
"test": "vitest run",
"server": "echo Server port: $npm_package_config_port"
}
}