Tools

ts-node

基础的 project 配置文件,与 tsconfig 相同,只是添加了 ts-node 配置项

  1. {
  2. // This is an alias to @tsconfig/node12: https://github.com/tsconfig/bases
  3. "extends": "../tsconfig.dev.json",
  4. // Most ts-node options can be specified here using their programmatic names.
  5. "ts-node": {
  6. // It is faster to skip typechecking.
  7. // Remove if you want ts-node to do typechecking.
  8. "transpileOnly": true,
  9. "files": true,
  10. "outDir": "./.ts-node",
  11. "compilerOptions": {
  12. // compilerOptions specified here will override those declared below,
  13. // but *only* in ts-node. Useful if you want ts-node and tsc to use
  14. // different options with a single tsconfig.json.
  15. }
  16. },
  17. "compilerOptions": {
  18. // typescript options here
  19. }
  20. }

运行时检查配置,可用于查看文件是否被 include,执行以下:

如不设置 include,exlude ,fiels 等,也没啥问题,但是会导致很多无用的内容被解析造成编译速度变慢

  1. ts-node --show-config

坑:ts-node 中如果配置了 files 为 true 时,会自动生成 files 配置,且该 files 中只包含与 confg.json 同层级及往内的内容。
所以如果需要指定一个外部文件进行执行(外部文件也有自己的依赖),需要 files 为 false。

transpileOnly 可以提速,因为会跳过类型检查。