debugging - VSCode : Automatically run npm script on starting debugging of a web project

标签 debugging npm visual-studio-code

所以这是我的 VS 代码 launch.json文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:4321",
            "port": 9222,
            "webRoot": "${workspaceFolder}"
        }
    ]
}

我想要的是运行 npm start调试开始前的命令,即运行开发服务器,然后启动 Chrome 实例并导航到提供的 url。

因此,我将以下代码段添加到配置文件并运行调试:
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
               "start"
            ]

但我收到了这个错误:
Attribute runtimeExecutable does not exist ('npm')

有什么帮助吗?

最佳答案

找到解决方案:我需要一个 preLaunchTasklaunch.json :

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Chrome against localhost",
            ...
            // This runs dev server before debugger
            "preLaunchTask": "start-dev-server",
        }
    ]
}
tasks.json :
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "start-dev-server",
            "type": "npm",
            "script": "start",
            "isBackground": true,
            "problemMatcher": {
                "owner": "npm",
                "background": {
                    "activeOnStart": true,
                     "beginsPattern": ".*",
                     "endsPattern": "Finished.+"
                },
                "pattern": {
                    "regexp": "",
                }
            }
        },
    ]
}

关于debugging - VSCode : Automatically run npm script on starting debugging of a web project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59509689/

相关文章:

ruby-on-rails - 如何像调试 Rails 应用程序一样调试 Sinatra 应用程序?

eclipse - 如何获取对象的 Eclipse 调试 ID?

node.js - 设置自定义全局目录后如何将 npm 更新到最新版本

node.js - 在 vscode 中调试时如何将 NODE_PATH 设置为 $(pwd)

c# - Visual Studio 2015 上缺少 "Edit and Continue"选项

javascript - 有没有办法在调试 JavaScript 时更改变量值?

node.js - NPM 依赖于计算机的操作系统吗?

node.js - NodeJS 需要带有路径的模块

c++ - Visual Studio 代码,#include <stdio.h> 说 "Add include path to settings"

visual-studio-code - vscode 片段变量