[Node] Use babel-preset-env with Native Node Features and Also Use Babel Plugins
2024-08-31 20:38:12
In this lesson we'll show how to setup a .babelrc
file with presets and plugins. Then create npm scripts that use babel-node
and babel
. With babel-preset-env
we'll show how to target specific versions of node and how to use babel plugins, while not transpiling features (like async
await
) that are already supported by node natively.
package.json:
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.5.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1"
},
.babelrc:
{
"presets": ["react", "es2015", ["env", {
"targets": {
"node": "current"
}
}]],
"plugins": ["transform-object-rest-spread"]
}
node: "current", compile code based on your node version.
Node version larger than 7.6 will have async/await support by defualt. So if we already have 7.6 above, we don't want Babel to compile async/await to ES5 code.
"presets": ["react", "es2015", ["env", {
"targets": {
"node": 7.6
}
}]]
最新文章
- 贝塞尔曲线(UIBezierPath)属性、方法汇总
- Gradle 刷新依赖
- Web开发人员必读的12个网站
- Sql Server事务简单用法
- ssh An internal error occured during ";Add Deployment";
- [转]使用onclick跳转到其他页面/跳转到指定url
- jenkins创建git任务连接时遇到的问题
- Hibernate 、继承关联映射
- Java Scanner 类
- PHP中cURL的应用
- 【Linux基础】大B和小b
- mysql export query result
- ORM框架学习之EF
- ifdown eth0或service network restart
- go-003-基础语法
- matlab实现MSER(最大极值稳定区域)来进行文本定位
- centos7 VNC安装
- python's metaclass
- 0821Servlet基础
- JeeSite基础知识(一)