以下是解决ES6转ES5时报错的四个文件:
- babel.config.js:
module.exports = (api) => {
api.cache(true);
const presets = [
[
'@babel/preset-env',
{
targets: '> 0.25%, not dead',
},
],
];
const plugins = [];
return {
presets,
plugins,
};
};
- .babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"targets": "> 0.25%, not dead"
}
]
],
"plugins": []
}
- package.json:
{
"name": "my-app",
"version": "0.1.0",
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": "> 0.25%, not dead"
}
]
],
"plugins": []
}
}
- webpack.config.js:
module.exports = {
// ...
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
// ...
};
暂无评论