可以将 Visual Studio Code 配置为使用 nodemon 启动吗 [英] Can Visual Studio Code be configured to launch with nodemon

查看:122
本文介绍了可以将 Visual Studio Code 配置为使用 nodemon 启动吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 nodemon 作为全局包安装在我的系统中.当我在 cmd 中执行 nodemon 时它起作用了.

I have installed nodemon as a global package in my system. It works when I executed nodemon in cmd.

但是当我在这个 launch.json 文件中使用 vscode 时,vscode 抛出这个异常:

But when I am using vscode with this launch.json file, vscode throws this exception:

请求启动:运行时可执行文件 XXX\XXX\XXX\XXX\nodemon 不存在

request launch: runtime executable XXX\XXX\XXX\XXX\nodemon does not exists

launch.json 是:

the launch.json is:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch",
        "type": "node",
        "request": "launch",
        "program": "app.js",
        "stopOnEntry": false,
        "args": [],
        "cwd": ".",
        "runtimeExecutable": nodemon,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "externalConsole": false,
        "preLaunchTask": "",
        "sourceMaps": false,
        "outDir": null
    },
    {
        "name": "Attach",
        "type": "node",
        "request": "attach",
        "port": 5858
    }
]
}

当我删除 runtimeExecutable 中的 nodemin 时,它与 node 完美运行

when I erase the nodemin in runtimeExecutable it runs perfectly with node

推荐答案

首先,安装 nodemon 作为开发依赖:

First, install nodemon as a dev dependency:

npm install --save-dev nodemon

对于较新版本的 VS Code,像这样设置 .vscode/launch.json 文件:

For newer versions of VS Code set up your .vscode/launch.json file like this:

{
    "version": "0.2.0",
    "configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "nodemon",
        "runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
        "program": "${workspaceFolder}/app.js",
        "restart": true,
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen"
    }]
}

最重要的部分是指向 nodemon 脚本的 runtimeExecutable 属性和指向您的入口点脚本的 program 属性.

The most important pieces are the runtimeExecutable property that points to the nodemon script and the program property that points to your entry point script.

如果您使用较旧的 VS Code(您不应该使用),请尝试以下启动配置:

If you use an older VS Code (which you shouldn't), try this launch configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch with nodemon",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/node_modules/nodemon/bin/nodemon.js",
      "args": ["${workspaceRoot}/app.js"],
      "runtimeArgs": ["--nolazy"]
    }
  ]
}

最重要的部分是指向 nodemon 脚本的 program 属性和指向普通入口点脚本的 args 属性.

The most important pieces are the program property that points to the nodemon script and the args property that points to your normal entry point script.

这篇关于可以将 Visual Studio Code 配置为使用 nodemon 启动吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆