如何在-VSCode-中使用-babelnode-调试-ES6代码

安装@babel/node

npm i @babel/node

目录结构

.
├── .babelrc
├── .vscode
│   └── launch.json
├── package.json

<!–more–>

配置launch.json

关键点:

  • 配置runtimeExecutable, 用babel-node来debug
  • 开启sourcemap "sourceMaps": true,
  • 配置env, 不影响babel其他功能
{
  // 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": "current file",
      "program": "${file}",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
      "sourceMaps": true,
      "env": {
        "BABEL_ENV": "debug"
      }
    }
  ]
}

配置.babelrc

说明:
debug对应launch.json中的 "BABEL_ENV": "debug"

{
  "presets": ["@babel/preset-env"],
  "env": {
    "debug": {
      "sourceMaps": "inline",
      "retainLines": true
    }
  }
}

givencui博客首发, 转载请注明来自GivenCui

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理