Node.js + Express + Typescript 환경 세팅법 입니다.
npm install express typescript ts-node
TypeScript로 짜여진 코드를 JavaScript로 컴파일하는 옵션을 설정하는 파일입니다. TypeScript 컴파일은 tsc 라는 명령어를 사용합니다.
아래 커맨드로 tsconfig.json 파일을 생성합니다.
$ npx tsc --init
아래 코드는 tsconfig.json 설정 예시입니다.
{
"compilerOptions": {
"target": "es6", // 어떤 버전으로 컴파일할지 작성
"module": "commonjs", //어떤 모듈 방식으로 컴파일할지 설정
"outDir": "./dist", //컴파일 후 js 파일들이 생성되는 곳
"rootDir": ".", //루트 폴더
"strict": true, //strict 옵션 활성화
"moduleResolution": "node", //모듈 해석 방법 설정: 'node' (Node.js)
"esModuleInterop": true,
"jsx": "react"
}
}