使用Babel编译
安装babel包babel-core``babel-loader``babel-plugin-transform-runtime``babel-polyfill``babel-preset-es2015
webpack.config.js 配置文件
modules.exports = {
...
entry: { name: ['babel-polyfill'], 'path/to/file.js' }, // 在入口文件添加babel-polyfill
....
module: {
rules: [
{
test: /.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
} // 添加loader
]
}
}
.babelrc 配置文件
{
"presets": [
"es2015"
],
"plugins": [
"transform-runtime"
]
}