通过vscode调试JavaScript代码,配置如下:
{
// 应用 IntelliSense 理解相干属性。
// 悬停以查看现有属性的形容。
// 欲了解更多信息,请拜访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// 通过npm脚本调试启动配置
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script", //第一个参数`run-script`不要批改
"escheck" //runtimeArgs的第二个参数,就是npm scripts的命令名
//对应package.json中的scripts中的escheck, 要求脚本必须是node调用
],
"port": 9229, //这个端口是调试的端口,不是我的项目启动的端口
"stopOnEntry": true //启动调试后会,会主动将断点停在代码的第一行
},
// 通过nodemon调试启动配置
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/app.js", // ${workspaceFolder}/app.js示意了调试的入口
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
我的项目package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "http-server ./",
"check": "es-check es5 './js/*.js'",
"escheck": "node --inspect-brk=9229 ./node_modules/.bin/es-check es5 './js/*.js'"
},
发表回复