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
}
三、更多参考
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: Nginx 中常用的模块整理
下一篇: 彻底找到 Tomcat 启动速度慢的元凶
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论