eggjs debug [vsCode]

使用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
    }
  ]
}

参考自官网 (https://eggjs.org/zh-cn/core/development.html)

你可能感兴趣的:(eggjs debug [vsCode])