如果你想调试编译后的代码,你必须在中定义构建任务tasks.json
然后将其指定为preLaunchTask
在你的launch.json
配置。
还要记住增强您的构建配置,以便它输出源映射。使用源映射,可以单步执行原始源代码或在原始源代码中设置断点。
You need to configure the tasks in a tasks.json
file (located under your workspace .vscode
folder). If you don't already have a tasks.json
file, running the Tasks: Configure Task Runner action from the Command Palette (⇧+⌘+P on macOS or F1 on Windows/Linux) will offer you a set of templates to pick from. Select Grunt
from the list and it will generate a file that should look like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "grunt",
"isShellCommand": true,
"args": ["--no-color"],
"showOutput": "always"
}
现在您可以定义构建任务:
{
...
"showOutput": "always",
"tasks": [
{
"taskName": "build",
"args": [],
"isBuildCommand": true
}
]
假设你的 Grunt 构建你的应用程序src/app.js
to dist
,您可以像这样定义启动配置:
{
"type": "node",
"request": "launch",
"name": "Launch",
"program": "${workspaceRoot}/src/app.js",
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/dist/**/*.js"],
"preLaunchTask": "build"
}
您可以在 VS Code 文档中阅读更多内容 -在 VS Code 中调试 Node.js https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_supported-nodelike-runtimes.