如何使用 ts 和 js build 查看文件更改

How to watch file changes with ts and js build

我有一个使用 fastify、apollo server fastify 和 nx 的项目。我想添加一个脚本来构建我的代码和 运行 js 文件。问题是,如果我对 ts 文件进行任何更改,它将无法识别重新 运行 js 文件。我应该怎么办? 顺便说一句,我不能将 ts-node 用于 运行nig 我的 ts 代码,因为我使用了自定义库,我必须先构建我的代码。

我当前的脚本:

"serve": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "tsc -p tsconfig.app.json -w",
          "tsc-alias -p tsconfig.app.json -w",
          "nodemon ../../dist/apps/server/authentication/index.js"
        ],
        "cwd": "apps/authentication",
        "parallel": true
      }
    }

我做了一个自定义执行器,我希望这对其他人有帮助:

    "start": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "nodemon -e ts,graphql --exec \"nx run server-authentication:start-nodemon\""
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },
    "start-nodemon": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "nx run server-authentication:ts-build",
          "node ../../../../dist/apps/server/authentication/src/index.js"
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },
    "ts-build": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "tsc -p tsconfig.app.json",
          "tsc-alias -p tsconfig.app.json",
          "ncp src/schema ../../../../dist/apps/server/authentication/src/schema",
          "ncp .env ../../../../dist/apps/server/authentication/src/.env"
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },