以下是解决ES6转ES5时报错的四个文件:

  1. babel.config.js:
module.exports = (api) => {
  api.cache(true);

  const presets = [
    [
      '@babel/preset-env',
      {
        targets: '> 0.25%, not dead',
      },
    ],
  ];
  const plugins = [];

  return {
    presets,
    plugins,
  };
};
  1. .babelrc:
{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": "> 0.25%, not dead"
      }
    ]
  ],
  "plugins": []
}
  1. package.json:
{
  "name": "my-app",
  "version": "0.1.0",
  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "targets": "> 0.25%, not dead"
        }
      ]
    ],
    "plugins": []
  }
}
  1. webpack.config.js:
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
    ],
  },
  // ...
};