# 一、自动升级

npx babel-upgrade --write --install

# 二、手动升级

# 2.1 安装依赖

// Babel-loader 8.x
"babel-loader"

// Babel-core 7.x
"@babel/core"

// Env
"@babel/preset-env"

// Runtime
"@babel/runtime"
"@babel/plugin-transform-runtime"

// React
"@babel/preset-react"

// Stage 0
"@babel/plugin-proposal-function-bind"

// Stage 1
"@babel/plugin-proposal-export-default-from"
"@babel/plugin-proposal-logical-assignment-operators"
"@babel/plugin-proposal-optional-chaining"
"@babel/plugin-proposal-pipeline-operator"
"@babel/plugin-proposal-nullish-coalescing-operator"
"@babel/plugin-proposal-do-expressions"

// Stage 2
"@babel/plugin-proposal-decorators"
"@babel/plugin-proposal-function-sent"
"@babel/plugin-proposal-export-namespace-from"
"@babel/plugin-proposal-numeric-separator"
"@babel/plugin-proposal-throw-expressions"

// Stage 3
"@babel/plugin-syntax-dynamic-import"
"@babel/plugin-syntax-import-meta"
"@babel/plugin-proposal-class-properties"
"@babel/plugin-proposal-json-strings"

# 2.2 修改.babelrc

{
  "presets": [
    ["@babel/preset-env", {
      "targets": {
        "browsers": [
          "last 2 versions",
          "Firefox ESR",
          "> 1%",
          "ie >= 9",
          "iOS >= 8",
          "Android >= 4"
        ]
      }
    }], "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-transform-runtime",

    "@babel/plugin-proposal-function-bind",

    "@babel/plugin-proposal-export-default-from",
    "@babel/plugin-proposal-logical-assignment-operators",
    ["@babel/plugin-proposal-optional-chaining", { "loose": false }],
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }],
    ["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }],
    "@babel/plugin-proposal-do-expressions",

    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    "@babel/plugin-proposal-function-sent",
    "@babel/plugin-proposal-export-namespace-from",
    "@babel/plugin-proposal-numeric-separator",
    "@babel/plugin-proposal-throw-expressions",

    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-syntax-import-meta",
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    "@babel/plugin-proposal-json-strings"
  ],
  "comments": false,
  "compact": false
}

# 三、更多参考

阅读全文