babel-cli
babel-cli是本地使用编译js文件
1.安装:
cnpm i babel-cli babel-preset-env -D
2.配置packjson:
"scripts": {
"build": "babel src -d dist"//babel 编译对象 -d 编译后存放地
}
3.配置.babelrc文件:
{
"preset": ["env"]
}
配合webpack
1.安装:
npm i babel-loader babel-core babel-preset-latest -D
2.配置webpack.config.js
module.exports = {
entrys: {
app: './src/main.js'
},
output:{
path: './dist',
name: 'js/[name]-bundle.js'
},
modules:{
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query:{presets:['env']}
}
]
}
}