Skip to content

Instantly share code, notes, and snippets.

@yungblud
Created March 4, 2020 02:50
Show Gist options
  • Select an option

  • Save yungblud/5c491b8db7e3830255cb6882ab126603 to your computer and use it in GitHub Desktop.

Select an option

Save yungblud/5c491b8db7e3830255cb6882ab126603 to your computer and use it in GitHub Desktop.
리액트, 타입스크립트 프로젝트의 절대경로 임포트
  1. tsconfig

tsconfig.json 쪽에 baseUrl 속성이 들어가야 한다.

  "complilerOptions": {
    ...
    "baseUrl": ".",
    ...
  },
  "extends": "tsconfig.paths.json"

그리고, extends로 별도의 tsconfig 파일을 상속한다.

tsconfig.paths.json

{
    "compilerOptions": {
        "paths": { "@app/*": ["src/*"] },
    }
}
  1. webpack
$ yarn eject

이젝트 하고, config/webpack.config.js 파일에 접근.

config/webpack.config.js

resolve: {
  ...
  alias: {
    ...
    '@app': path.resolve(__dirname, '../src'),
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment