Skip to main content

Babel

Flow 和 Babel 旨在完美配合。只需几个步骤即可将它们设置在一起。

¥Flow and Babel are designed to work great together. It takes just a few steps to set them up together.

如果你还没有安装 Babel,可以按照 本指南 进行安装。

¥If you don't have Babel setup already, you can do that by following this guide.

一旦你安装了 Babel,请安装 @babel/preset-flowbabel-plugin-syntax-hermes-parser 以及 Yarnnpm

¥Once you have Babel setup, install @babel/preset-flow and babel-plugin-syntax-hermes-parser with either Yarn or npm.

yarn add --dev @babel/preset-flow babel-plugin-syntax-hermes-parser
# or
npm install --save-dev @babel/preset-flow babel-plugin-syntax-hermes-parser

然后将 @babel/preset-flow 预设和 babel-plugin-syntax-hermes-parser 插件添加到你的 Babel 配置中。

¥Then add the @babel/preset-flow preset and babel-plugin-syntax-hermes-parser plugin to your Babel config.

{
"presets": ["@babel/preset-flow"],
"plugins": ["babel-plugin-syntax-hermes-parser"],
}

你可以阅读 babel-plugin-syntax-hermes-parser 的文档来了解如何配置它。该网站的 Babel 配置 提供了一个带有自定义解析器选项的示例。

¥You can read the documentation of babel-plugin-syntax-hermes-parser to see how to configure it. This website's Babel config provides an example with custom parser options.