依赖

需要安装 @babel/preset-react @babel/preset-env @babel/core babel-loader core-js@3

项目配置

webpack

  1. module:{
  2. rules:[
  3. {
  4. test: /\.jsx?$/,
  5. use: ['babel-loader']
  6. }
  7. ]
  8. }

babel.config.js

  1. module.exports = {
  2. presets: [
  3. ['@babel/preset-env', {
  4. useBuiltIns: 'usage',
  5. corejs: 3
  6. }],['@babel/preset-react'],
  7. ],
  8. plugins: [
  9. ['react-refresh/babel']
  10. ]
  11. }

.browserslistrc

  1. > 1%
  2. last 2 version
  3. not dead