[英]What governs the ECMAScript version in a create-react-app?
I am currently running a create-react-app, using react v16.2.我目前正在使用 react v16.2 运行一个 create-react-app。 I would like to use Optional chaining from ECMAScript 2021 (ES12).
我想使用 ECMAScript 2021 (ES12) 中的可选链接。 What governs the ECMAScript version in my app?
什么管理我的应用程序中的 ECMAScript 版本?
For example, in a nodejs backend app I know I need to upgrade my version of node, but I'm unsure how this translates to React.例如,在 nodejs 后端应用程序中,我知道我需要升级我的节点版本,但我不确定这如何转化为 React。
EDIT - I'm currently on v16.2 and when i try to use optional chaining, I get an error message asking me to use a babel polyfill.编辑 - 我目前使用的是 v16.2,当我尝试使用可选链接时,我收到一条错误消息,要求我使用 babel polyfill。
React uses Babel to transpile and polyfill the code ie convert your ES2015+ code to ES5 syntax. React 使用Babel来转换和填充代码,即将你的 ES2015+ 代码转换为 ES5 语法。
create-react-app
uses Webpack as the build tool and Babel as the transpiler so you should safely be able to use the optional chaining ?
create-react-app
使用 Webpack 作为构建工具,使用 Babel 作为转译器,所以你应该可以安全地使用可选链?
syntax and when you run / build your app, it will work as intended.语法,当您运行/构建您的应用程序时,它将按预期工作。
Babel is what decides this, it's a JS-to-JS transpiler. Babel 决定了这一点,它是一个 JS 到 JS 的转译器。 In create-react-app, you get whatever plugins and presets the maintainers decided on, unless/until you decide to eject so you can manage your own config.
在 create-react-app 中,您可以获得维护者决定的任何插件和预设,除非/直到您决定弹出以便您可以管理自己的配置。 If you do decide to do that, you can start with the config they provide and then add new babel presets and plugins on top of that.
如果你决定这样做,你可以从他们提供的配置开始,然后在其上添加新的 babel 预设和插件。 As of a couple years ago , there's no good way to add to their config without ejecting.
几年前,没有什么好的方法可以在不弹出的情况下添加到他们的配置中。 For your specific need, it looks like they include that plugin , so if your dependencies are up to date, you should be good to go.
对于您的特定需求,看起来它们包含该插件,因此如果您的依赖项是最新的,您应该可以使用 go。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.