[TS] TypeScript Compiler 학습

Toproot·2021년 9월 2일
0

TypeScript

목록 보기
1/5
post-thumbnail

1. Compilation Context

Compilation Context

The compilation context is basically just a fancy term for grouping of the files that TypeScript will parse and analyze to determine what is valid and what isn't. Along with the information about which files, the compilation context contains information about which compiler options are in use. A great way to define this logical grouping (we also like to use the term project) is using a tsconfig.json file.

2. tsconfig schema

# 실습 폴더 생성
mkdir compilation-context
cd compilation-context

# ts 기본 프로젝트 생성
npm init -y
npm i typescript -D
npx tsc --init

3. compileOnSave

"compileOnSaveDefinition": {
	"properties": {
		"compileOnSave": {
			"description": "Enable Compile-on-Save for this project.",
				"type": "boolean"
		}
	}
},
  • true / false (default false)

  • 누가??

4. extends

  • 상속
"extendsDefinition": {
	"properties": {
		"extends": {
			"description": "Path to base configuration file to inherit from. Requires TypeScript version 2.1 or later.",
				"type": "string"
		}
	}
},
  • 파일(상대) 경로명: string

  • TypeScript 2.1 New Spec (2.1 이상에서만 사용 가능)

    tsconfig/bases

# 최근 새롭게 제시되는 상속방법. => 향후 많이 쓰일 것 같음.
{
	"extends" : "@tsconfig/deno/tsconfig.json",
	...
}

🔥 5. files, include, exclude

  • 어떤 파일을 컴파일 할 것인지 결정.

files

"filesDefinition": {
	"properties": {
		"files": {
			"description": "If no 'files' or 'include' property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories except those specified by 'exclude'. When a 'files' property is specified, only those files and those specified by 'include' are included.",
				"type": "array",
				"uniqueItems": true,
				"items": {
				"type": "string"
			}
		}
	}
},
  • files가 가장 센 형태의 선정. 우선순위 높음

exclude

"excludeDefinition": {
	"properties": {
		"exclude": {
			"description": "Specifies a list of files to be excluded from compilation. The 'exclude' property only affects the files included via the 'include' property and not the 'files' property. Glob patterns require TypeScript version 2.0 or later.",
				"type": "array",
				"uniqueItems": true,
				"items": {
					"type": "string"
			}
		}
	}
},
  • files에는 영향을 주지 않음.
  • Globpatterns : gitignore같은 제외 대상 설정

include

"includeDefinition": {
	"properties": {
		"include": {
			"description": "Specifies a list of glob patterns that match files to be included in compilation. If no 'files' or 'include' property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories except those specified by 'exclude'. Requires TypeScript version 2.0 or later.",
			"type": "array",
			"uniqueItems": true,
			"items": {
				"type": "string"
			}
		}
	}
},

정리

  • 셋다 설정이 없으면, 전부다 컴파일
  • files
    • 상대 혹은 절대 경로의 리스트 배열입니다.
    • exclude 보다 셉니다.
  • include, exclude
    • glob 패턴( 마치 .gitignore)
    • include
      • exclude 보다 약합니다.
        • 같은 걸 사용하면, .ts / .tsx / .d.ts 만 include (allowJS)
    • exclude
      • 설정 안하면 4가지(node_modules, bower_components, jspm_packages, )를 default 로 제외합니다.
      • 은 항상 제외 합니다. (include에 있어도)
profile
어디로 튈 지 모르는 개발자 로그 🛴

0개의 댓글