如何通过TS和JS构建观看文件更改

发布于 2025-01-25 17:08:50 字数 543 浏览 4 评论 0原文

我有一个带有Fastify,Apollo Server Fastify和NX的项目。我想添加一个脚本来构建我的代码并运行JS文件。问题是,如果我对TS文件进行任何更改,则无法识别重新运行JS文件。我应该怎么办? 顺便说一句,我无法将TS节点用于我的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
      }
    }

I have a project with fastify, apollo server fastify and nx. I want to add a script to build my code and run the js files. the problem is that if I make any changes in ts file it wont recognize to re run the js files. what should I do?
btw I can't use ts-node for runnig my ts code because I have used custom libraries and I have to first build my code.

my current script:

"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
      }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼角的笑意。 2025-02-01 17:08:50

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

    "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
      }
    },

I made a custom executor, I hope this help someone else:

    "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
      }
    },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文