Typescript 환경 구성 - Part.1 Typescript 설치 및 기본 환경 설정

누군가·2024년 2월 18일
0

Typescript 환경 구성

목록 보기
2/3
post-thumbnail

Typescript 설치

  • 이 문서는 NPM (Node Package Manager)를 통해 설치하는 방식으로 작성되었습니다.
  • Typescript는 Node.js 관점에서 볼 때 NPM Module 중 하나이므로, 사전에 Node.js 및 NPM이 설치되어 있어야 합니다.
  • Node.js 설치 참조

1. Node.js 프로젝트 초기화

  • 아래 명령어를 통해 프로젝트 경로에 Node.js 프로젝트를 초기화합니다.
# Node.js 프로젝트 초기화
> npm init (프로젝트 명, 버전 등 프로젝트 정보 입력)
또는
> npm init -y (프로젝트 정보를 기본값으로 설정)

2. Typescript 모듈 설치

  • 아래 명령어를 통해 현재 프로젝트 경로에 Typescript 모듈을 설치합니다.
# Typescript 모듈 설치
> npm install typescript (현재 프로젝트 경로에 Typescript 모듈 설치)
또는
> npm install typescript -g (전역 경로에 Typescript 모듈 설치, 어떤 경로에서든 Typescript 컴파일 가능)

3. Typescript 초기화 (tsconfig.json 파일 생성)

# tsconfig.json 파일 생성
> tsc --init
또는
> npx tsc --init (전역 경로에 Typescript 모듈을 설치하지 않은 경우)

  • tsconfig.json 파일이 생성되었다면 프로젝트에 맞게 Typescript 설정을 적용합니다.
{
  "compileOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "dist",
    "skipLibCheck": true,
    "strict": true
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

compileOptions: Typescript 컴파일 시 적용되는 설정
compileOptions.target: 타겟 JS 버전
compileOptions.module: 모듈 방식
compileOptions.outDir: Typescript 컴파일 후 결과물 저장 경로 (.js 파일)
compileOptions.skipLibCheck: Library 파일 검사를 스킵하여 컴파일 시간 절약
compileOptions.strict: 광범위한 유형 검사 동작 활성화 여부
include: 컴파일 시 포함될 파일 또는 경로
exclude: 컴파일 시 제외할 파일 또는 경로

소스코드

Reference

https://curryyou.tistory.com/527

https://www.typescriptlang.org/tsconfig

profile
개발 중에 알게된 내용을 공유합니다 (나도 기억할겸)

0개의 댓글