TypeScript 컴파일 하기 (watch 모드)

Namlulu·2022년 3월 2일
0

TypeScript

목록 보기
1/2

개요 TS > JS로 컴파일

  1. tsc를 활용하여 JS파일을 떨군다.
  2. concurrently와 nodemon으로 watch 환경을 구성한다.

tsconfig

  1. src/밑에 ts코드를 dist/경로 밑으로 컴파일
{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Language and Environment */
    "target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,

    /* Modules */
    "module": "commonjs" /* Specify what module code is generated. */,
    "outDir": "dist" /* Specify an output folder for all emitted files. */,
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  }
}

명렁어 수정

  1. concurrently를 통해 컴파일과 node 실시간 수행을 동시에 수행
{
  "name": "tsc",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "concurrently \"tsc -w\" \"nodemon dist/main.js\""
  },
  "devDependencies": {
    "concurrently": "^7.0.0",
    "nodemon": "^2.0.15"
  }
}
profile
Better then yesterday

0개의 댓글