1、安装babel-cli
npm i babel-cli -D
2、实现npm的初始化
npm init -y
3、配置package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib" //src 表示需要转换的文件夹,lib表示转换后的目标文件夹
},
"keywords": [],
"author": "",
"license": "ISC"
}
4、安装版本文件
npm i babel-preset-env -D
5、创建 .babelrc
配置文件
{
"presets": ["env"]
}
6、实现转换
npm run build