ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • TS 컴파일러
    JavaScript/TypeScript 2021. 6. 18. 02:02

     

    Compilation Context

     

    - 컴파일할 파일, 컴포넌트 등의 모음

    - 컨텍스트에는 컴파일러가 어떠한 에러도 없이 컴파일 하는데 필요한 모든 것을 포함

    - TS를 컴파일할 때 컨텍스트를 files, include 또는 exclude 옵션을 사용한 tsconfig.json 파일로 제어

     

    tsconfig schema

     

    최상위 속성(Property)

    • compileOnSave
    • extends
    • compileOptions
    • files
    • include
    • exclude
    • references

     

    compileOnSave

     

    - true / false (기본값 false)

     

    "compileOnSave": true  

    파일을 저장 (Save)하면 컴파일 하겠다

     

    extends

     

    - 파일 (상대) 경로명: string

     

    "extends": "./파일명"
    "extends": "./base.json"

    명시한 파일의 설정을 상속받는다

     

    files, include, exclude

     

    셋 다 설정이 없으면, 전부 컴파일

     

    files

    - 상대 혹은 절대 경로의 리스트 배열,

    - exclude 보다 쎔

     

    include

    - glob 패턴 (.gitinore 같은 형식)

    - exclude 보다 약함

    - * 같은걸 사용하면 .ts/ .tsx. / .d.ts 만 include (allowJS)

     

    exclude

    - glob 패턴 (.gitinore 같은 형식)

    - <outDir>은 항상 제외

    - 설정을 안하면 4가지(node_modules, bower_components, jspm_packages, <outDir>)를 default 로 제외

     

    files 사용 예제
    
    {
        "compilerOptions": {
            "module": "commonjs",
            "noImplicitAny": true,
            "removeComments": true,
            "preserveConstEnums": true,
            "sourceMap": true
        },
        "files": [
            "core.ts",
            "sys.ts",
            "types.ts",
            "scanner.ts",
            "parser.ts",
            "utilities.ts",
            "binder.ts",
            "checker.ts",
            "emitter.ts",
            "program.ts",
            "commandLineParser.ts",
            "tsc.ts",
            "diagnosticInformationMap.generated.ts"
        ]
    }

     

    include와 exclude 사용 예제
    
    {
        "compilerOptions": {
            "module": "system",
            "noImplicitAny": true,
            "removeComments": true,
            "preserveConstEnums": true,
            "outFile": "../../built/local/tsc.js",
            "sourceMap": true
        },
        "include": [
            "src/**/*"
        ],
        "exclude": [
            "node_modules",
            "**/*.spec.ts"
        ]
    }

     

    compileOptions

     

    @types

    - 내장 type definition 시스템

    - 아무 설정을 안하면 node_modules/@types 라는 모든 경로를 찾아서 가져옴

     

    typeRoots

    - 배열 안에 들어있는 경로들 아래서만 가져옴

     

    types

    - 배열 안의 모듈 혹은 ./node_modules/@types/ 안의 모듈 이름에서 가져옴

    - [] 빈 배열을 넣는다는건 이 시스템을 이용하지 않음

     

    typesRoots와 types를 같이 사용하지 않는다

     

    target

    - 빌드의 결과물을 어떤 버전으로 하는지 지정

    - 지정을 안하면 es3

     

    lib

    - 기본 type definition 라이브러리를 어떤 것을 사용하는지 지정

    - lib를 지정하지 않으면

    1. target 은 'es3', 디폴트로 lib.d.ts 를 사용

    2. target 은 'es5', 디폴트로 dom, es5, scripthost 를 사용

    3. target 은 'es6', 디폴트로 dom, es6, dom.iterable, scripthost 를 사용

    - lib를 지정하면 그 lib 배열로만 라이브러리를 사용

    - 빈 [] => 'no definition found ~'

     

    outDir

    - 출력되는 디렉토리를 설정

     

    outFile

    - 복수 파일을 묶어서 단일 파일로 합쳐서 출력

     

    rootDir

    - 입력 파일들의 루트 디렉토리 설정. --outDir 옵션을 사용해 출력 디렉토리 설정이 가능

     

    strict

     

    - 기본값 true 

    - 타입을 엄격하게 확인하는 옵션을 활성화 시킴 (true)

    - 아래의 옵션을 모두 활성화

     

    --nolmplicitAny - false 라면 명시적이지 않게 any 타입을 사용하여, 표현식과 선언에 사용하면 에러를 발생

    --nolmplicitThis - false 라면 명시적이지 않게 any 타입을 사용하여, this 표현식에 사용하면 에러를 발생

    --strictNullChecks - false 라면 모든 타입은 null, undefined 값을 가질 수 있다

    --strictFunctionTypes - false 라면 인자 타입이 공변적 이면서 반공변적인 것이 문제이다

    --strictPropertyInitialization - false 라면 정의되지 않은 클래스의 속성이 생성자에서 초기화 되지 않으면 에러를 발생

    --strictBindCallApply - true 라면 bind, call, apply 에 대한 엄격한 검사 수행

    --alwaysStrict - 각 소스 파일에 대해 js 의 strict mode 로 코드를 분석하고, "엄격하게 사용"을 해제

    'JavaScript > TypeScript' 카테고리의 다른 글

    TS 클래스  (0) 2021.06.23
    TS 인터페이스  (0) 2021.06.19
    TS 타입 시스템  (0) 2021.06.17
    TS 타입  (0) 2021.06.12
    TS 설치  (0) 2021.06.12

    댓글

Designed by Tistory.