# 在 vscode 中调试

VSCode launch.json配置详解

# 自动生成的 nodejs

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "启动程序",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}"
        }
    ]
}

这种配置是比较万能的,只要选定了代码,就可以直接运行当前代码。如果需要制定文件是这样的

{
    "program": "${workspaceFolder}/src/index.js"
}

# 关于 request

启动配置必须设定请求类型,属性 request , 分为 launch (启动) 和 attach(附加)两种

# 使用 attach(附加)

{
    "name": "Attach by Process ID",
    "processId": "${command:PickProcess}",
    "request": "attach",
    "skipFiles": [
        "<node_internals>/**"
    ],
    "type": "pwa-node"
}

# 带有参数的调试

{
    "type": "node",
    "request": "launch",
    "name": "调试参数",
    "skipFiles": [
        "<node_internals>/**"
    ],
    "runtimeExecutable": "node",
    "args": [
        "${workspaceFolder}/bin/cli.js",
        "js",
        "a.js",
        "-t",
        "vue"
    ]
}

# 直接运行命令

{
    "type": "node",
    "request": "launch",
    "name": "启动程序",
    "skipFiles": [
        "<node_internals>/**"
    ],
    "runtimeExecutable": "npm",
    "runtimeArgs": ["run", "build"]
}