美文网首页
VSCode调试Node.js的ES6/7特性

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

作者: scue | 来源:发表于2017-11-04 20:30 被阅读126次

    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

    相关文章

      网友评论

          本文标题:VSCode调试Node.js的ES6/7特性

          本文链接:https://www.haomeiwen.com/subject/qojqmxtx.html