Node.js在保存时编译

问题描述 投票:0回答:2

由于自动生成的tsconfig文件,我有一个Angular应用程序编译保存,但我无法弄清楚如何为Node.js服务器做同样的事情。我是否需要修改launch.json以某种方式引用另一个tsconfig.json?

这是我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "ng serve",
            "type": "chrome",
            "request": "launch",
            "preLaunchTask": "npm: start",
            "url": "http://localhost:4200",
            "webRoot": "${workspaceFolder}"
          },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch JS",
            "program": "${workspaceFolder}/src/app/nodeapi/nodeapi.js"
        }
    ]
}

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

我的项目结构:

|src
|-app
|--app.component.ts and other .TS files
|--nodeapi
|---nodeapi.js <---contains my server code
|tsconfig.json (shown above)
node.js visual-studio-code vscode-tasks
2个回答
0
投票

您可以使用nodemon来保存您的应用程序将自动编译


0
投票

您可以使用Angular CLI安装nodemon。 Nodemon是一个任务监视器,它会在保存时自动编译服务器端/ API。

© www.soinside.com 2019 - 2024. All rights reserved.