[Issue] Typescript Path Alias가 선언 파일(.d.ts)에 그대로 남아있는 문제

cutehammond·2023년 3월 9일
0

Front-End

목록 보기
1/1

배경

필자가 React 라이브러리를 개발하고 있는 도중, 빌드 과정에서 생성된 선언 파일에 Path Alias가 그대로 남아있는 것을 발견하였다.

Path Alias는 tsconfig.json의 compilerOptions 옵션 중 paths를 통해 설정할 수 있으며, 절대 경로에 별칭을 설정하여 간결하게 import를 할 수 있게 해 준다.

해결법

  • ttypescript, typescript-transform-paths 라이브러리 설치
$ yarn global add ttypescript
$ yarn add -D ttypescript typescript-transform-paths
  • tsconfig.jsoncompilerOptions에 다음과 같이 설정을 추가
"plugins": [
  {
    "transform": "typescript-transform-paths",
    "afterDeclarations": true
  }
]
  • 빌드 시 명령어를 tsc 대신 ttsc를 사용
$ ttsc -p "./tsconfig.json"

추가 (2023.3.22)

Typescript가 v5.0.2 (Stable)로 업데이트되면서, ttypescript의 Patch 기능이 막혔다.

Issue: Not working on TS 5.0 (#140)

현재로서는 방법이 없다고 하니 v4.9.x로 다운그레이드하도록 한다.

profile
People who hesitate cannot move forward.

0개의 댓글