lbr*_*him 4 node.js visual-studio-code
我手动添加了一个配置start:debug,但 VS Code 又显示了另一个配置。两者都执行应用程序,但当我运行我的应用程序时,它不会在终端中显示所有应用程序控制台输出,例如错误、日志等。但是当我运行 VS Code 时,一切都会完美运行,我更喜欢在我们的团队中使用该配置。
问题是我无法签入配置,因此在另一台机器上它没有按预期显示。VS Code 如何获取该配置并执行它?如果我可以在我的配置中复制它,那么我可以在我的存储库中检查它以供其他人使用。
以下是解开谜团的步骤:按照以下步骤,您将发现难以捉摸的选项的任务配置设置,并发现它是如何添加到您的列表中的:
so-70196209创建一个空文件夹(我以此问题 ID命名),然后在新的 VS Code 工作区中打开它。
package.json在文件夹中创建一个文件。确保它有一个start:debug像这样的脚本条目:
package.json:
{
"name": "so-70196209",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start:debug": "echo \"Success\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
}
Run Code Online (Sandbox Code Playgroud)
在 VS Code 菜单中,选择“运行”>“添加配置...”
在出现的列表中,选择“Node.js”:
.vscode/launch.json将使用如下默认任务创建一个文件:
.vscode/launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果您不想保留此默认任务,可以稍后删除它,但暂时保留它并继续进行到底。
选择活动栏中的“运行和调试”图标。
在“运行和调试”侧栏中,选择下拉菜单并选择“Node.js...”:
在出现的列表中,找到带有文本“Run Script: start:debug”的条目。找到右侧的齿轮图标,然后选择齿轮。
如果将鼠标悬停在齿轮上,将出现一个工具提示,其中包含文本“在 launch.json 中编辑调试配置”
这将向 中添加一个新条目.vscode/launch.json,并且该条目就是您一直在搜索的条目。(它不在您的启动配置中,而是在您的下拉列表中的原因是因为您之前在某个时刻单击了输入行,但没有单击齿轮。我不知道为什么这会将其添加到下拉列表中并且不是配置,但这就是它现在的工作方式。)
配置文件现在看起来像这样:
.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
},
{
"type": "node-terminal",
"name": "Run Script: start:debug",
"request": "launch",
"command": "npm run start:debug",
"cwd": "${workspaceFolder}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
“运行和调试”下拉菜单现在包含您想要的条目:
问题解决了!
| 归档时间: |
|
| 查看次数: |
2998 次 |
| 最近记录: |