VSCode调试Node.js的ES6/7特性

2017-11-04  本文已影响126人  scue

PS: 文章中的yarn是npm管理包的另一个实现,下载速度更快。

  1. init a module:
yarn init -y
  1. babel setup
yarn add babel-cli babel-core babel-preset-env --dev

and edit .babelrc:

{
  "presets": ["env"]
}
  1. and my package.json file
{
    "name": "node",
    "version": "1.0.0",
    "description": "尝试玩一玩",
    "main": "index.js",
    "author": "scue",
    "license": "MIT",
    "scripts": {
        "start": "babel-node index.js",
        "debug": "babel-node debug index.js"
    },
    "devDependencies": {
        "babel-cli": "^6.26.0",
        "babel-core": "^6.26.0",
        "babel-preset-env": "^1.6.1"
    }
}
  1. and my .vscode/launch.json file
{
    // 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": "attach",
            "name": "Attach",
            "port": 9229
        },
        {
            "type": "node",
            "request": "launch",
            "protocol": "inspector",
            "name": "Launch Program",
            "program": "${workspaceFolder}/index.js",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
            "runtimeArgs": ["--presets", "env"]
        }
    ]
}

node -v # v8.7.0

screenshot:

image
上一篇下一篇

猜你喜欢

热点阅读