目录
1. Babel 是什么?
2. Babel 能干什么?
3. Babel 核心构成
4. 一个小 Demo
1. Babel 是什么?
Babel 是一个工具链,主要用于将 ECMAScript 2015+ 版本的代码转换为向后兼容的 JavaScript 语法,以便能够运行在当前和旧版本的浏览器或其他环境中。
2. Babel 能干什么?
Babel 能为你做的事情:
示例:ES2015 语法转换
示例:JSX 语法转换
示例:TypeScript 语法转换
3. Babel 核心构成
4. 一个小 Demo
安装依赖:
npm install --save-dev @babel/core
npm install --save-dev @babel/cli
npm install --save-dev @babel/preset-env
npm install --save-dev @babel/preset-react
npm install --save-dev @babel/preset-typescript
配置Babel(babel.config.json):
{
"presets": [
"@babel/env",
"@babel/react",
"@babel/preset-typescript"
]
}
scripts:
babel src --out-dir lib
scripts:
参考:
babel 官网: https://babeljs.io/docs/en/