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

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • This project was bootstrapped with Create React App. Belo...
    unspecx阅读 5,232评论 0 2
  • 一、ES6 参考 http://es6.ruanyifeng.com/ ECMAScript当前所有提案 Git...
    pifoo阅读 11,876评论 1 13
  • 1. 配置webpack+babel 这部分与前端工程的配置方式相同,只多了SourceMap和npm scrip...
    何幻阅读 7,411评论 0 6
  • 随着时间的推移,浏览器对ES6支持度已经越来越高了,超过90%的 ES6 语法特性都实现了。虽然有些浏览器对ES6...
    无亦情阅读 2,720评论 0 6
  • 其实这次旅行算的上是说走就走的吧,没什么计划,纯粹的想换个环境。也许是因为闲到怀疑人生吧,有点郁闷,想出去看看这个...
    MrET阅读 645评论 0 1