使用 es6 调试、实时编译 nodejs 程序
发布于 8 年前 作者 su-rm-rf 7099 次预览 最后一次回复是 8 年前 来自 分享
目标:
使用 es6 调试 和 实时编译 nodejs 程序
需要用到:
编辑器:vscode
自动重启:nodemon
babel编译:babel、babel-node、babel-preset-env
安装依赖
yarn global add nodemon babel-core
yarn add babel-preset-env
配置
package.json
"scripts": {
"start": "nodemon --inspect --watch <path> --exec babel-node --presets env <path>/server.js"
}
babel配置
{
"presets": ["env"],
"retainLines": true
}
vscode配置
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
}
]
运行
步骤:
- npm start
- 启动 vscode 调试功能
调试效果
如下图:左侧看debug信息、中间看调试代码、左下角看实时编译
github地址:点我查看
2 回复
node不是已经支持es6了吗,为何还要babel
@luluzero es6模块还不支持呢