⌨️/TypeScript

[TypeScript] 프로젝트 생성 및 셋팅

S0 2024. 3. 6. 10:40

 

 

 

npm init -y

프로젝트 초기화

 

 

tsc --init --rootDir ./src --outDir ./dist --esModuleInterop --module commonjs --strict true --allowJS true --checkJS true

tsc --init

tsconfig.json 파일 생성

-> 타입스크립트 프로젝트로 변환

 

--rootDir ./src 

-> 프로그램의 소스 파일이 들어가는 경로 설정(해당 프로젝트는 src 폴더 기준)

--outDir ./dist 

-> 컴파일 된 파일들이 들어가는 디렉토리 경로 설정

--esModuleInterop 

-> CommonJS 모듈을 ES 모듈 방식의 import 구문으로 가져옴

--module commonjs 

-> 타입스크립트 파일을 컴파일한 후 생성되는 자바스크립트 모듈의 형식 지정

--strict true 

-> 엄격한 타입 검사 옵션을 모두 활성화하는 옵션

--allowJS true 

-> 타입스크립트 프로젝트에 자바스크립트 파일 허용 여부

--checkJS true

-> 자바스크립트 파일 타입 체크 여부

 

 

"scripts": {
    "start": "tsc && node ./dist/index.js",
    "build": "tsc --build",
    "clean": "tsc --build --clean"
},

package.json의 scripts 항목 변경

(프로젝트를 간편하게 실행)