导航
导航
文章目录󰁋
  1. 一、自动升级
  2. 二、手动升级
    1. 2.1 安装依赖
    2. 2.2 修改.babelrc
  3. 三、更多参考

关注作者公众号

和万千小伙伴一起学习

公众号:前端进价之旅

babel升级7.xx总结

一、自动升级

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
}

三、更多参考

支持一下
扫一扫,支持poetries
  • 微信扫一扫
  • 支付宝扫一扫