absolute path

· Frontend
Preiew babel.config.js에 경로를 추가합니다. tsconfig.json에 경로 추가해서 vscode가 인식할 수 있게 만들어줍니다. metro server 캐시를 리셋해줍니다. (이것 때문에 삽질함) babel.config.js "babel-plugin-root-import", { paths: [{ rootPathSuffix: "./src", rootPathPrefix: "~/" }], }, src/components 디렉토리를 절대경로로 추가해보겠습니다. "babel-plugin-root-import", { paths: [ { rootPathSuffix: "./src", rootPathPrefix: "~/" }, { rootPathSuffix: "./src/components", roo..
· Frontend
테스트파일 절대경로 설정 상대경로가 너무 깊어지면 모듈을 import할때 매우 더러워지기 때문에 바벨, tsconfig.json에서 절대경로를 설정한다. 하지만 테스트 파일을 위한 절대경로는 따로 설정해줘야 한다. 당연히 jest.config.js에서 설정을 해야하며 아래와 같이 경로의 alias를 설정해 줄 수 있다. moduleNameMapper: { '^components/(.*)': '/components/$1', '^hooks/(.*)': '/hooks/$1', }, 맨 앞을 나타내는 정규표현식인 ^를 처음에는 안 써줬었는데 계속 path를 못 찾는 에러가 발생했다. ^를 써주니 $1 그룹도 잘 찾고 에러없이 테스트 파일을 실행시킬 수 있..
mechaniccoder
'absolute path' 태그의 글 목록