analogcoding

react + typescript 절대경로 import 본문

Be well coding/Mine

react + typescript 절대경로 import

be well 2020. 5. 15. 13:11

babel-plugin-module-resolver 플러그인 추가

 

babel.config.js 해당 플러그인 추가 후 alias 에 별칭  : 주소 형태로 저장

plugins: [
    [
      'module-resolver',
      {
        root: ['.'],
        alias: {
          '~': './src',
          '~buttons': '.src/components/buttons',
        },
      },
    ],
  ],

 

tsconfig 에 baseUrl 과 paths 추가

"baseUrl": "./src"
    "paths": {
      "~/*": ["./*"],
      "~buttons/*": ["components/buttons/*"]
    },
Comments