【问题标题】:Subfolders not being compiled for dev未为 dev 编译子文件夹
【发布时间】:2019-02-01 06:37:42
【问题描述】:

我正在使用 TypeScript 创建我的 nodejs 应用程序,该应用程序运行良好,因为 index.ts 正在成功编译和执行,但子文件夹中的 TypeScript 文件被忽略并且不构成开发监视的一部分。

有人可以帮忙吗?我使用yarn start 在开发模式下运行我的应用程序。我来自package.json 的脚本如下所示:

"scripts": {
  "start": "yarn run build:live",
  "build": "rm -rf dist && tsc",
  "build:live": "nodemon --exec ./node_modules/.bin/ts-node -- ./src/index.ts"
}

而我的tsconfig.json 看起来像这样:

{
  "compilerOptions": {
    "outDir": "dist",
    "target": "es2017",
    "module": "commonjs",
    "sourceMap": true,
    "noUnusedLocals": true,
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/**.ts",
    "test/**/**.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

我曾尝试使用"build:live": "nodemon --exec ./node_modules/.bin/ts-node --project tsconfig.json" 作为我的开发脚本,但这会导致编译器挂起。

【问题讨论】:

    标签: node.js typescript nodemon ts-node


    【解决方案1】:

    ts-node 只会执行你的主文件src/index.ts 需要或导入的文件。您可以使用--files 选项使其在编译中包含tsconfig.json 中指定的所有文件,但这仅有助于声明事物,而不是在运行时定义它们。见the documentation。如果您需要在不使用 require 或 import 的情况下执行所有文件,请考虑使用其他工具运行您的项目。

    【讨论】:

      猜你喜欢
      • 2013-01-08
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 2020-07-30
      • 2020-04-02
      • 2010-10-23
      • 2015-01-06
      • 2018-06-21
      相关资源
      最近更新 更多