babel 编译踩坑记录

1,332 阅读1分钟

babel不会转译Proxy

Unsupported feature

Due to the limitations of ES5, Proxies cannot be transpiled or polyfilled. See support in various JavaScript engines.


参考链接:babeljs.io/docs/en/lea…

项目中使用了mobx5,导致低版本浏览器报错。因为mobx5使用了Proxy

参考链接:www.npmjs.com/package/mob…

参考链接:mobx.js.org/best/pitfal…


可考虑使用Proxy的polyfill(暂未验证)github.com/GoogleChrom…

或者降低mobx版本


query-string不会被编译成es5

This module mainly targets Node.js, not the browser. It's up to you to transpile it with Babel if you want to use it in the browser. You can find a more detailed explanation here: sindresorhus/ama#446

参考链接:github.com/sindresorhu…

自己写一个url处理工具方法

或者降低query-string到5.x版本(暂未验证)


babel配置

{  "presets": [["@babel/preset-env"], ["@babel/preset-react"]],  "plugins": [    [      "@babel/plugin-transform-runtime",      {        "corejs": 3      }    ],    [      "@babel/plugin-proposal-decorators",      {        "legacy": true      }    ],    [      "@babel/plugin-proposal-class-properties",      {        "loose": true      }    ],  ]}

使用以上配置即可