1. package.json
{
"scripts": {
"build": "tsc",
"start:dev": "tsc-watch --onSuccess \"node dist/app.js\"",
=> tsc-watch를 실행하여, 지속적으로 ts 파일을 js파일로 변환하고,
컴파일이 완료될 경우 dist 폴더에 있는 app.js를 실행
"prestart": "npm run build",
=> prestart는 start 명령어 실행 전에 자동으로 실행함.
=> build 시, tsc가 실행됨.
"start": "node dist/app.js"
},
"devDependencies": {
"@types/express": "^4.17.13", => express라는 프레임워크에서 ts로 개발하기 위해 필요함
"@types/node": "^15.3.0", => node.js의 타입들을 의미
"prettier": "^2.2.1", => 코드 포맷팅하는 pretieer
"tsc": "^2.0.3", => typescript 컴파일러
"tsc-watch": "^4.2.9", => ts로 작성된 파일들에 변경사항이 있을 때, 지속적 컴파일 실행
"typescript": "^4.3.4"
}
}
2. tsconfig.json
{
"compilerOptions": {
"strict": true,
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES5",
"sourceMap": true,
"outDir": "./dist", // 컴파일된 결과물이 저장될 경로
"baseUrl": "./src", // 컴파일을 실행할 경로
"incremental": true
},
"include": ["src/**/*"] // src에 있는 모든 파일들에 tsconfig.json의 설정들이 적용됨.
}