체인의정석

typescript 커스텀 모듈 만들 시 발생가능한 에러사항 본문

개발

typescript 커스텀 모듈 만들 시 발생가능한 에러사항

체인의정석 2021. 7. 22. 17:59
728x90
반응형

1. 경로를 절대경로로 사용할 시에 에러가 발생한다.

절대 경로로 설정해 줄 경우 모듈을 설치하였을 때 인식을 잘 하지 못한다. 따라서 상대경로로 모두 바꾸어준다.

 

2. 필요없는 test와 같은 폴더는 build에서 빼고 src 나 lib같이 코드가 모여 있는 부분만을 빌드하여야 한다.

 

tsconfig.json

{
  "compilerOptions": {
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2019",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
    "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
    "incremental": true,
    "paths" : {
      "@lib/*": ["./lib/*"],
      "@test/*": ["./test/*"]
   }
  },
  "include": ["./lib/**/**.ts" ],
  "exclude": ["./node_modules", "test/**/**.ts",]
}

 

다음과 같이 tsconfig에서 include안에는 필수적인 값만 넣도록 한다.

test 경로에 있을 시 exclude를 해준다.

 

3. dist 폴더로 나온 파일을 원래 디렉터리에서 그대로 올려준다.

모듈이 아닌 경우 dist 폴더는 gitignore에서 빼두지만 모듈인 경우 git ignore를 사용하여 dist를 빼면 안된다. build까지 진행한 후에 나온 dist 폴더에 있는 소스 코드를 모듈에서 찾아서 사용하기 때문에 dist를 올려주면 된다. 또한 외부에 공개해야할 경우 소스 코드 없이 dist 경로의 코드만 공개하여도 모듈로서 사용할 수 있다.

728x90
반응형
Comments