【问题标题】:Node.js compile on saveNode.js 在保存时编译
【发布时间】:2019-04-10 04:46:47
【问题描述】:

由于自动生成的 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


    【解决方案1】:

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

    【讨论】:

    • 安装 nodemon 后,我需要修改哪些文件?启动配置?
    • @Rilcon42,您不必为此修改任何文件。您必须在命令提示符中为此运行命令 nodemon nodeapi.js
    【解决方案2】:

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

    【讨论】:

    • 安装 nodemon 后,我需要修改哪些文件?启动配置?
    猜你喜欢
    • 2011-09-11
    • 1970-01-01
    • 2015-07-11
    • 2014-01-24
    • 1970-01-01
    • 2014-07-15
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多