ts-node 應用

github page

ts-node是直接執行typescript使用的,若是不想做tsc的動作而直接執行的話可以直接利用

ts-node <path-to-file>
直接去做執行

這中間當然可以套用一些其他的options不過簡單執行這個即可

注意:因為ts-node是執行typescript,所以先確定系統當中是否已經安裝typescript

一開始當然先說起手勢啦

yarn global add ts-node
上一篇提到了yarn那就當然用yarn來做安裝的動作啦

安裝期間東西會有點多,網速慢的大概要注意一下

雖然說ts-node可以直接執行typescript的程式,但是實際上執行情況是先將typescript先compile後放在cache中,然後再做執行,所以並不會像nodejs運行js檔案那樣來的快速,中間還是會有經過一次編譯的動作

該報錯還是會報錯,不過好處是它會直接trace到.ts的檔案,一般的.map.js檔案如果當中沒有註冊或者安裝其他套件做設定的話,最高一層只會追蹤到js就停止,並不會往上追到原始碼去

Options:
  -e, --eval [code]              Evaluate code
  -p, --print [code]             Evaluate code and print result
  -r, --require [path]           Require a node module for execution
  -C, --compiler [name]          Specify a custom TypeScript compiler
  -I, --ignoreWarnings [code]    Ignore TypeScript warnings by diagnostic code
  -D, --disableWarnings          Ignore every TypeScript warning
  -P, --project [path]           Path to TypeScript project (or \`false\`)
  -O, --compilerOptions [opts]   JSON object to merge with compiler options
  -F, --fast                     Run TypeScript compilation in transpile mode
  --ignore [regexp], --no-ignore Set the ignore check (default: \`/node_modules/\`)
  --no-cache                     Disable the TypeScript cache
  --cache-directory              Configure the TypeScript cache directory
這部份是source code當中所接受的arguments

說實話我根本沒用過((喂!

有用過得只有fast原本在進行ts-node的時候會進行type的確認,假若說要省略掉這一動作,就要加上此參數

下一篇介紹live-server

留言

這個網誌中的熱門文章

ubuntu 日常(X)紀錄

Angular 2 with Third Party files