使用egg腳手架搭建好最基本的項目后,當我們想調試代碼時,該怎么做呢?你還是選擇不斷得console.log?太low了,那么該怎么debug呢?
本文針對 Node.js 7.x 及之后的版本 ( 7.0以下的版本使用第二種方案)
1.在根目錄創建 .vscode目錄,下面創建 launch.json
按F5啟動即可
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Egg",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"windows": { "runtimeExecutable": "npm.cmd" },
"runtimeArgs": [ "run", "debug" ],
"console": "integratedTerminal",
"protocol": "auto",
"restart": true,
"port": 9999
}
]
}
2.在根目錄創建 .vscode目錄,下面創建 launch.json
在 Terminal 手動執行 npm run debug
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach Egg Worker",
"type": "node",
"request": "attach",
"restart": true,
"port": 9999
}
]
}