假如原来 package.json 里有个脚本 "prod": "node ./start.js"
, 为了在调试状态运行这个脚本,在 package.json 中新建一个脚本 "debug": "node --inspect-brk=9229 ./start.js"
,这里的 --inspect-brk=9229
会让进程启动后在 9229 端口监听(这句话不确定准确性,我现在是这样认为的)。然后点左边的 debug 图标,新建一个 configuration 如下
{
// 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": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"debug"
],
"port": 9229
},
]
}
点绿色的运行箭头,vs code 会在 debug 状态下运行,设置断点,开始调试。
网友评论